Skip to main content
Associate III
January 11, 2024
Question

SPI DMA example

  • January 11, 2024
  • 3 replies
  • 17861 views

hi, i m using STM32H7 and have running SPI using interrupt transmittng and receiving from external ADC, now i m contemplating using DMA for SPI transmit and receive, but was not able to get any data reponse from the ADC. could anyone kindly advise any sample code on SPI DMA normal or circular mode? I have code the following functions, what be inside the DMAReceiveCpltDMA callback functions? should i create another callback for DMATxCpltDMA ? 

spi_tx(t_data)

spi_rx_tx(data)

DMAReceiveCplt(DMA_HandleTypeDef *hdma)

3 replies

AScha.3
Super User
January 11, 2024

Hi,

first set the two dma channels , rx + tx , in Cube as circular , enable callbacks .

AScha3_0-1704958758778.png

 

then..

 

 

HAL_DMA_Init(&hdma_spi1_rx);
HAL_DMA_Init(&hdma_spi1_tx);

fresult = HAL_SPI_Receive_DMA(&hspi1, ESPinbuf , (sizeof(ESPinbuf)));	// ESP input-loop start
fresult = HAL_SPI_Transmit_DMA(&hspi1, ....);

 

 

Then in callbacks use data & set data ...btw why send data stream to ADC ? is useful ? 

"If you feel a post has answered your question, please click ""Accept as Solution""."
Associate III
January 11, 2024

System requirement for external ADC.. what should  i code inside the callback function? anyone sample working code to start with? 

AScha.3
Super User
January 11, 2024

what should  i code inside the callback function?

what you want to do . I dont know what you need to send to the adc... , you didnt tell even which adc, 

but in rx half- and full- callbacks you have to use the data block , = copy to an array for FFT or ... I dont know what you want to do .

So "sample working code"  for --- what ?

"If you feel a post has answered your question, please click ""Accept as Solution""."
Associate III
January 11, 2024

Hi anyone can advise sample code on SPI DMA using stm32cubeMX not register. 

TDK
Super User
January 11, 2024

> Hi anyone can advise sample code on SPI DMA using stm32cubeMX not register. 

Use the Example Selector in STM32CubeMX to find SPI DMA examples. They are there.

"If you feel a post has answered your question, please click ""Accept as Solution""."