Skip to main content
Associate III
July 25, 2024
Solved

STM32 SPI2 Not Receiving Data via DMA Despite Clock Generation.

I have an ADC connected to an STM32-L4P5DK. Data should be read in the background by the DMA controller. SPI TX is assigned to DMA1 CHANNEL2, and SPI RX is assigned to DMA1 CHANNEL3. Both DMA1 CHANNEL2 and CHANNEL3 are synchronized with EXTI1 (DRDY signal from the ADC). The STM32 SPI2 is configured as a full-duplex master. Both SPI TX(to transmit dummy bytes) and RX are synchronized with the external interrupt (pin PD1 is assigned to DRDY). 

The problem is that I can see the data on the scope, but SPI2 is not receiving any data.

I start TX using the function:

 

 

HAL_SPI_Transmit_DMA(&hspi2, tx, 0x1b);

 

 

And receive the transmission using:

 

 

HAL_DMA_Start_IT(&hdma_spi2_tx, (uint32_t)adc_buf, (uint32_t)&(SPI2->DR), 0x1b);
SET_BIT(SPI2->CR2, SPI_CR2_RXDMAEN);

 

 

 

DMA1 CHANNEL1, set to very high priority, is used to pull the chip select pin low on the DRDY falling edge. This channel generates a DMA request to control the CS pin.

adc_out.jpeg

Yellow - DRDY from ADC , Green - CS , Red - SCK , Blue - MISO. 

 

SPI RX config:

ajmw__0-1721890010959.png

SPI TX config.

ajmw__1-1721890064626.png

 

Regards,
Aji

 

 

This topic has been closed for replies.
ajmw_Best answer
Associate III
July 25, 2024

Thank you, @BarryWhit, for your response.

The issue was with the function call. Instead of passing the &hdma_spi2_rx handle, the &hdma_spi2_tx handle was passed.
correct usage:

 

HAL_DMA_Start_IT(&hdma_spi2_rx, (uint32_t)adc_buf, (uint32_t)&(SPI2->DR), 0x1b);
SET_BIT(SPI2->CR2, SPI_CR2_RXDMAEN);

 

 

5 replies

BarryWhit
Lead
July 25, 2024

Can you receive data when using the blocking API? try to start simple and make sure things are working, and only then move to DMA.

 

Are you sure you're using the DMA synchronization correctly? the idea is to synchronize incoming DMA request to the synchronizing event. So, something (peripheral, software) is supposed to generate a DMA request (i.e to transfer a word) and this request is only actually forwarded to the DMA peripheral when the synchronization event occurs.

What is generating the DMA requests in your design? 

 

> This channel generates a DMA request to control the CS pin.

What do you mean by that? Isn't the DMA configured to move data over SPI? 

"- If someone's post helped resolve your issue, please thank them by clicking ""Accept as Solution"".- Please post an update with details once you've solved your issue. Your experience may help others."
ajmw_Author
Associate III
July 25, 2024

 

Hi Barry,

Initially, I used the SPI in blocking mode, followed by SPI DMA without synchronization, and both worked fine. However, when I tried SPI DMA with synchronization, I encountered the issue mentioned above.

BarryWhit
Lead
July 25, 2024

See my updated response, can you provide more information?

"- If someone's post helped resolve your issue, please thank them by clicking ""Accept as Solution"".- Please post an update with details once you've solved your issue. Your experience may help others."
ajmw_AuthorBest answer
Associate III
July 25, 2024

Thank you, @BarryWhit, for your response.

The issue was with the function call. Instead of passing the &hdma_spi2_rx handle, the &hdma_spi2_tx handle was passed.
correct usage:

 

HAL_DMA_Start_IT(&hdma_spi2_rx, (uint32_t)adc_buf, (uint32_t)&(SPI2->DR), 0x1b);
SET_BIT(SPI2->CR2, SPI_CR2_RXDMAEN);