cancel
Showing results for 
Search instead for 
Did you mean: 

SPI DMA example

StanCosgrove
Associate II

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)

8 REPLIES 8
AScha.3
Chief II

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".

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

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".

for spi_tx function i need to send 0480 hex to ADC, for spi_rx function i need to read back what ADC transmit ...O.. there is another rx half full callback? what should code inside the rx half full?  i need an workng sample code on spi dma, cos i m a student using STM for the first time.. 

TI ADC TLV1570 

ADC TLV1570 -- May i ask, why you connect a 8 channel 1 Msample 10bit adc to a cpu, that has about 20adc channels on 2 or 3 adcs with 12 ...16bit and with > 3 Msample speed ?  To learn something ? ( what ??)

 

>there is another rx half full callback?

Exactly.

Seems, you have no plan, whats going on in the circular dma... or double buffer dma.

Search for circular dma and double buffer dma , read about ... then decide, what you want to do with the data - and then do it.

 

>i need an workng sample code

look on git - there is almost everything.

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

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

TDK
Guru

> 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".