This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SSI/SPI - Processing efficiency when reading 32bit values

Gentlemen,

I just wrote code to read 32 bit values from an SPI sensor, using the "old style" 2 wire MISO/MOSI. Given the limitation of 16bit FIFO and configuration parameters, this is what is working well for me:

GPIOPinWrite(GPIOFSSBase,GPIOFSSPin,0);					// Lower CSB
SSIDataPut(SSI0_BASE, frameHigh); 						// Sends only the upper 16 bits
while(SSIBusy(SSI0_BASE));
SSIDataGet(SSI0_BASE, &readCrap);						// Read useless data
SSIDataPut(SSI0_BASE, (frameLow));						// This sends the other 16 bits
while(SSIBusy(SSI0_BASE));
GPIOPinWrite(GPIOFSSBase,GPIOFSSPin,GPIOFSSPin);		// Raise CSB
SSIDataGet(SSI0_BASE, &readCrap);						// Read useless data
GPIOPinWrite(GPIOFSSBase,GPIOFSSPin,0);					// Lower CSB
SSIDataPut(SSI0_BASE, frameHigh); 						// Flush 16 more bits
while(SSIBusy(SSI0_BASE));								// Wait for bits to be flushed out
SSIDataGet(SSI0_BASE, &read16High);						// Read 16 bits
SSIDataPut(SSI0_BASE, frameLow); 						// Flush 16 more bits
while(SSIBusy(SSI0_BASE));								// Wait for bits to be flushed out
SSIDataGet(SSI0_BASE, &read16Low);						// Read more data
GPIOPinWrite(GPIOFSSBase,GPIOFSSPin,GPIOFSSPin);		// Raise CSB

I wonder if you have any more efficient suggestions? The while()'s are probably not the most elegant solution. But at 8MHz SPI communication, I'm not sure it would be worth the trouble of trying to implement DMA's or even interrupts... Anyone willing to share experience?

The SPI configuration is at 8MHz, and the clock on the TM4C1294 is at 120Mhz. FSS is controlled by software for there are more sensors on the same data lines. For what is worth, the above lines take 11us to complete (no optimizations).

By the way, I guess there's a lot of legacy motives for such, but ain't it counterintuitive to implement 16bit FIFO's on a 32bit part?

  • Hello Bruno

    The TM4C129x has the advanced mode of operation where 8 bit is the size of the. You can see the example code for the same in the Serial Flash example code in the software of the following reference design.

    www.ti.com/.../TIDM-TM4C129SDRAMNVM
  • Yes, but that would require even more code deviation to service every 8 bits... Or maybe implement DMA on four 8-bit transfers is actually more efficient?

    The "doubt" here is, given the 8MHz clock of this particular SPI, I wonder that just the management of program execution pointers and deviations are such overhead, that the background SPI solution would be slower than the less elegant while(waiting_for_transmission) one...
  • Hello Bruno

    If that is the case, then using DMA would be more efficient in terms of offloading the data write and read from the SSI FIFO. However setup of the DMA needs to be done which may cause some overhead.
  • Amit,

    I guess there's no better answer than "do it an measure the results"...

    This board reads 4 different sensors at a rate of 2300Hz. That's 9200 cycles per second, each cycle with 6x 32-bit words. That's a lot of SPI reading, it is the most I ever asked from a Tiva. But my basic measurements on the code still show there's enough processing power left for the numeric processing and off-board communications.

    Since my typical work-scenario is "get it working and move to the next project", I may not have time to test a DMA solution so soon - but I hope I can do it sometime, and I'll share the results here.

    And note to myself: again, I wished I had already mastered TI-RTOS... It would be so much easier to control executions and measure available processor... So when I eventually read this message again, let it be that my ongoing projects are already RTOS'ed!

    Regards,
  • Hello Bruno,

    At this point, "no". You would need to evaluate the right use model for the use case you have. TI-RTOS uses RAM to relocate the interrupt vector table, so that may affect RAM usage in your end application.