2020-12-30 03:32 AM
Hi, I have a STM32F407 board that is running as a full duplex slave. it receives data from a Raspberry Pi configured as a SPI master.
Is there a way to receive data from the RPi in a non-blocking mode? One way I could think of was to set the CSN line as a falling interrupt and then call the receive function within the callback. Unfortunately, I've run out of interrupts (many many endstops!).
I tried starting the SPI comm using interrupt mode but that does not seem to work. It transferred only the first two bytes (of the 42 bytes I wanted to transfer). I will try the DMA but I believe that too does a one time transfer and then stops(?)
Any other ideas?
Solved! Go to Solution.
2020-12-30 06:02 AM
You can receive with SPI either in interrupt or DMA mode. One particularly efficient implementation is to receive into a circular buffer and periodically monitor how many bytes have been received (by examining the NDTR register) and process the data.
Normal DMA will do one time transfer, circular DMA will receive indefinitely.
2020-12-30 06:02 AM
You can receive with SPI either in interrupt or DMA mode. One particularly efficient implementation is to receive into a circular buffer and periodically monitor how many bytes have been received (by examining the NDTR register) and process the data.
Normal DMA will do one time transfer, circular DMA will receive indefinitely.
2020-12-30 08:33 AM
Thanks. The DMA with circular buffer worked. However, since its a circular buffer, wouldn't the NDTR always show the number of bytes of the array you would be storing the incoming data in? I put the NDTR check in my while 1 loop and it never changed to any value beyond the array size I had defined (42 bytes).
2020-12-30 09:01 AM
2020-12-30 09:48 AM
Wrapped back around seems more likely since data in the RX buffers is updating correctly. Thanks again for the suggestion. This was helpful!