cancel
Showing results for 
Search instead for 
Did you mean: 

How to use SPI DMA on slave

KR51K
Associate III

Hi,

I would like use the DMA functionality for SPI on my STM32F4. But all examples I have found are calling the SPI DMA Transmit Receive function in a while loop. But what would be a better way? I think that if I call the Transmit Receive function when CS goes low is to late. So would it be good to trigger on the rising edge so that the data is available when the Mster triggers the next transfer? Or do you now a link for a good example?

2 REPLIES 2
TDK
Guru

What I do is have SPI set up to transfer a circular buffer and poll the NDTR register to determine if new data came in, and if so, populate the buffer with the response to send out. This works, except that due to buffers you need to send 2 or 3 dummy bytes before reading new data from the slave.

There's no one size fits all solution here. It will depend on the protocol between the master and the slave. If you know the response at the rising edge of CS, then triggering on that seems like a good idea. But if you need to read and interpret the first few bytes sent by the master in order to formulate a response, then it doesn't work so well.

If you feel a post has answered your question, please click "Accept as Solution".
KR51K
Associate III

Thanks for your answer. Yes, I'm using a fixed protocol with a fixed length (10 words). I tried it out but the received data on the slave is shifted, so the first word of each transfer is the last word from the last transmission (not using circular buffer). I thought, if I start the transfer on the rising edge of CS where the last transfer is finished this could not happen... Any ideas?