Skip to main content
Visitor II
April 6, 2024
Question

HAL_ADC_Start_DMA from HAL_ADC_ConvCpltCallback

  • April 6, 2024
  • 2 replies
  • 1574 views

Hi :)

I would like to acquire n samples from one channel of the on-board ADC (set at 4MHz) every time my EXTI line gets a rising edge (about 25Hz). I am on a STM32L496 on its Nucleo board.

I am using ADC1 IN8 single-ended and I am using Regular Conversion as EXTI trigger. I have Continous Conversions enabled and DMA enabled as well.

I am starting the conversion with `HAL_ADC_Start_DMA` from the main, which saves the data in a buffer and calls the `HAL_ADC_ConvCpltCallback` once the conversion is done. Now I would like to restart the conversion from the interrupt, but if I call `HAL_ADC_Start_DMA(hadc, ...);` from inside the interrupt I don't get any more conversions. On the other hand, if I call again `HAL_ADC_Start_DMA` from the main the system works as intended.

Can I restart the conversion inside the Callback? Is this even the right way to do it?

Thank you!!

    This topic has been closed for replies.

    2 replies

    Visitor II
    April 9, 2024

    Any thoughts from the community? :)

    ST Employee
    April 18, 2024

    Hello @mgiordyeth,

    In your situation, I believe the optimal approach would be to employ the DMA in circular mode, which eliminates the necessity to restart the ADC.

    You can reference the ADC_DMA_Transfer example as a guide. By enabling the circular mode, you would set the DMA mode as follows:

     

     

    DmaHandle.Init.Mode = DMA_CIRCULAR;

     

     

    Regards,

    Rania