2

How to correctly and repetitively stop and restart ADC with DMA in STM32L476RG?

I need to measure signal a number of samples before the trigger and a number of samples after the trigger.

I set: DMA in circular mode, ADC in continuous conversion mode, DMA continuous requests, overrun data overwritten, 1 channel, sampling time 2.5 cycles

I start ADC with: HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_buffer, ADC_BUFFER_LEN and it waits for the trigger.

When I get the trigger I let to fill DMA buffer till next HAL_ADC_ConvHalfCpltCallback or HAL_ADC_ConvCpltCallback and in the callback I use HAL_ADC_Stop_DMA(hadc1).

When it is stopped I make processing the data and then I try to restart ADC with HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_buffer, ADC_BUFFER_LEN).

Unfortunately it doesn't start anymore. Do you have any suggestions why it doesn't restart or how to make better this scenario to get samples before and after the random triggers?

hooboe
  • 133
  • 8
  • Compare ADC and DMA registers before the first working conversion burst and before the second non-working one (after calling HAL_ADC_Start_DMA). See if there is any difference in their configurations, the callback could be ruining something, maybe HAL_ADC_Stop_DMA resets some DMA config. Or at least check out the ADC and DMA registers after the second HAL_ADC_Start_DMA. You have to see something misconfigured there. – Ilya Jun 12 '23 at 13:40
  • Are any of the HAL functions returning an error? I did a project where I stop and start the ADC with DMA (albeit on an STM32F030) and it worked fine. I didn't have to do anything unusual. – pmacfarlane Jun 12 '23 at 15:24

0 Answers0