I2C SPI USB CAN eSPI Cable Testing View All Quick Start Guides User Manuals Software Downloads Knowledge Base Videos Case Studies App Notes White Papers Sales Support About Us
Products Blog Sales Support Contact Search
How Do I Batch API Commands for High-Speed SPI Devices?
Rena Ayeras

Question from the Customer:

Can you help me use Cheetah Software API commands correctly? I am using the Cheetah SPI Host Adapter running SPI at 1 MHz. I am trying to repeatedly send the target device four bytes of data (4, 41, 0, 0), as shown in the command sequence below.

However, after adding two repeats to the queue and the final batch shift command, the return values are not what I expect.

  • The first set of four bytes are correct: [0,0,0,172].
  • However, the second set of four bytes are [0, 0, 0, 0], not the repeated [0,0,0,172] that I expect to see.

If I add the commands Assert SS and Deassert SS between the two groups of the four-byte values during the queue, then the batch shift returns the correct values, [0,0,0,172, 0,0,0,172].

However, using the SS Assert and Deassert commands add an interval of 10 microseconds between sending the two groups of values. I cannot accept this result. That time interval must be no greater than 1 microsecond.

Can you tell me how I can get the send set of four bytes to have the same values as the first set of four bytes?  Here are the details, the API command sequences and the output result:

The command sequence:
ch_spi_queue_clear(1)      # Clear the queue first.

ch_spi_queue_oe(1, 1)

ch_spi_queue_ss(1, 0x1)     # Assert SS

ch_spi_queue_byte(1, 1, 4 )

ch_spi_queue_byte(1, 1, 41 )

ch_spi_queue_byte(1, 1, 0x00)

ch_spi_queue_byte(1, 1, 0x00)

ch_spi_queue_byte(1, 1, 4 )

ch_spi_queue_byte(1, 1, 41 )

ch_spi_queue_byte(1, 1, 0x00)

ch_spi_queue_byte(1, 1, 0x00)

ch_spi_queue_ss(1, 0)      # Deactive slave.

(count, data_in) = ch_spi_batch_shift(1,  8 )

print ("\ncount: ", count)

print ("data_in: ", data_in)

 The output:
Starting the program ...

creating Cheetah instance ...

connecting Cheetah ...

Opened Cheetah device on port 0

Host interface is high speed

SPI configuration set to spi_mode 0, MSB shift, SS[2:0] active low

Bitrate set to 1000 kHz

byte1: 4,    byte2: 41

self handle: 1

 

count:  8

data_in:  array('B', [0, 0, 0, 172, 0, 0, 0, 0])

 Response from Technical Support:

Thanks for your question! The command queue is fine; you only need to “batch” the commands. When using the Cheetah Software API to send SPI data across the bus at high speed, commands are accumulated in a queue until a call is made to batch shift all the queued commands. Here is a summary of sequencing the commands for an SPI transaction queue:

  1. Clear the command queue: ch_spi_queue_clear
  2. Add a command to the queue to enable the Cheetah devices outputs on the SPI bus: ch_spi_queue_oe
  3. Add a command to the queue to enable the slave select signal: ch_spi_queue_ss
  4. Queue the data to be sent across the SPI bus: ch_spi_queue_byte and ch_spi_queue_array
  5. Queue a command to disable the slave select signal: ch_spi_queue_ss

    • Optionally, you can call ch_spi_queue_oe to queue a command to disable the outputs of the Cheetah device.

  1. Send the accumulated commands across the SPI bus: ch_spi_batch_shift

In step 4, the ch_spi_queue_byte and ch_spi_queue_array functions execute in a synchronous manner; they are executed sequentially in the order in which they were queued. Each function is executed after the previous line is completed. Processing is not allowed to continue until it returns to the calling thread. For this reason, we recommend using the command for the CS line to rise after the data queues are completed.

For additional information about the Cheetah API SPI transactions, please refer to the section SPI Overview in the Cheetah SPI Host Adapter User Manual.

We hope this answers your questions. Additional resources that you may find helpful include the following:

If you want more information, feel free to contact us with your questions, or request a demo that applies to your application.

Request a Demo