Skip to main content
Visitor II
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)

    This topic has been closed for replies.

    3 replies

    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 ? 

    Visitor II
    January 11, 2024

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

    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 ?

    Visitor II
    January 11, 2024

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

    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.