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.
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 )The output:print ("\ncount: ", count)
print ("data_in: ", data_in)
Starting the program ...Response from Technical Support: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])
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:
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.