Issue with SPI Data Reception in Receive-Only Mode in STM32L4 with DMA for ADC Data Capture - DMA Synchronization
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2024-11-11 2:18 AM - edited 2024-11-17 9:32 PM
I’m working on reading an ADC that’s interfaced with an STM32L4RET6, and I’m encountering an issue with data reception when switching SPI modes. Here’s the setup:
- The ADC has a data rate of 8000 Hz, so I receive a DRDY (active low) signal every 125 µs.
- DMA1 Channel 1 is configured as DMA_GENERATOR0 to handle the DRDY falling edge, which triggers a DMA request. This request sets the Chip Select (CS) low by writing to the GPIOX_BRR register and also generates an event.
- DMA1 Channel 2 is assigned to SPI1_RX, synchronized with DMAMUX1 Channel 0 event (linked to DMA1 Channel 1) to trigger the SPI1 receive operation, capturing 6 bytes of ADC data.
- SPI1 is configured in full-duplex mode in CubeMX, and once ADC configuration is complete, RX_ONLY mode is enabled to set SPI1 as a receive-only master, generating a continuous SPI clock.
- On each DRDY falling edge, DMA1 Channel 1 triggers the Chip Select, and SPI1 then receives ADC data. In the SPI_RxCpltCallback(), I reset the RX_ONLY bit to stop the SCK and set the CS pin high again and In the EXTI_Callback() I set the RX_ONLY bit to start the SCK for next cycle.
The issue arises when switching from full-duplex to receive-only mode on the SPI: while the ADC configuration works in full-duplex, no data is received by the SPI after enabling RX_ONLY mode. Any ideas on why this might be happening or suggestions on how to troubleshoot this?
Solved! Go to Solution.
- Labels:
-
DMA
-
GPIO-EXTI
-
SPI
-
STM32CubeMX
-
STM32L4 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2024-11-17 9:31 PM
I resolved the issue by configuring SPI1 in full-duplex mode and synchronizing only SPI1_TX with DMAMUX CHANNEL0 Event. SPI1_RX was set to circular mode, allowing me to read all ADC channel data (27 bytes) every 125 µs (8 ksps) as per the setup below.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2024-11-17 9:31 PM
I resolved the issue by configuring SPI1 in full-duplex mode and synchronizing only SPI1_TX with DMAMUX CHANNEL0 Event. SPI1_RX was set to circular mode, allowing me to read all ADC channel data (27 bytes) every 125 µs (8 ksps) as per the setup below.
