AnsweredAssumed Answered

SPI Using DMA Sends Duplicate Bytes...

Question asked by Ian Morris on Jan 24, 2014
Latest reply on Nov 10, 2015 by JOSEP LLUIS MORALES

Hi,

 

I'm using a Kinetis KL14 and am trying to implement the Proessor Expert SPI interface as Master. The device I am connecting to requires multiple bytes to be transferred without raising the CS pin in between bytes; therefore I believe I have to use the SPI interface with DMA so it can keep up - tt seems to ALMOST work, but I have noticed some strange behaviour...

 

If I have the SPI clock rate set to 1MHz, and I attempt to send 12 bytes of data, it actually sends 13 (confirmed with oscilloscope) and it is the first byte that is repeated twice. The sent data count reads as 12, and send status reads as complete.

 

If, however, I have the clock rate set higher (e.g. 2MHz, 4Mhz) the same thing happens, HOWEVER only ever on the FIRST time.... repeated attempts will then always send the correct 12 bytes as expected. UNTIL I call the 'cancel transmission' function, at which point the problem resets; i.e. the first send is broken, subsequent sends work as expected.

 

There is a slightly cryptic note in the reference manual which seems vaguely relevant:

After DMA transfers the first byte to the SPI data register, the SPI pushes this data into

the shifter, thereby making SPTEF high again. This generates another DMA request

immediately, but the CPU lacks enough time to service the first DMA interrupt service

request (ISR). The subsequent DMA request is paced at the SPI transfer rate. Manage this

behavior during the first byte transfer through the DMA channel. Write the first byte to

the SPI data register via the CPU. The other bytes are transmitted by the DMA.

 

This seems to suggest that the first byte should be handled differently, although I can not see whether this is happening in the PE generated code. I have attempted to manually send the first byte, however this leaves a long gap between the first byte and those that follow it, which is not acceptable for my implementation.

 

I guess my question is: is there a known bug in the SPI DMA implementation, or am I just using it wrong? And if so, how do I implement a reasonably fast and reliable SPI Master interface....?

 

Any help would be much appreciated....

 

Ian

Outcomes