2020-05-23 12:59 PM
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?
2020-05-23 03:54 PM
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.
2020-05-23 08:17 PM
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?