Running SPI receive in the background
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-30 3: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.
- Labels:
-
SPI
-
STM32F4 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-30 6: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-30 6: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-30 8: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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-30 9:01 AM
If it's stuck at 42, it's not receiving data (or it wrapped back around already).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-30 9: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!
