Skip to main content
Associate
January 20, 2025
Question

adc continuous conversion with DMA for stm32f407G

  • January 20, 2025
  • 2 replies
  • 1130 views

i have an example code which reads the adc value in continuous conversion mode with dma. I have done all the  initialization part but its doesn't work for contionus conversion which shows some random values for adc.But it do work for single conversion. The only changes made is  i have disabled the continuous for single conversion.

AdcHandle.Instance = ADCx;

 

AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;

AdcHandle.Init.Resolution = ADC_RESOLUTION_12B;

AdcHandle.Init.ScanConvMode = DISABLE;

AdcHandle.Init.ContinuousConvMode = DISABLE;

AdcHandle.Init.DiscontinuousConvMode = DISABLE;

AdcHandle.Init.NbrOfDiscConversion = 0;

AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1;

AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;

AdcHandle.Init.NbrOfConversion = 1;

AdcHandle.Init.DMAContinuousRequests = ENABLE;

AdcHandle.Init.EOCSelection = DISABLE;

 

if(HAL_ADC_Init(&AdcHandle) != HAL_OK)

{

/* Initialization Error */

Error_Handler();

}

why it is not working for continuous conversion mode with DMA ,if i have change the code to AdcHandle.Init.ContinuousConvMode = ENABLE;

2 replies

Technical Moderator
January 20, 2025

Hello @AiswaryaLakshmi ,

 

First let me thank you for posting and welcome to the ST Community.

For more investigation, I suggest that you provide the STM32CubeMX version that you are using.

 

Thanks

Mahmoud

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Ozone
Principal
January 20, 2025

This setup does make limited sense.
Continuous conversion immediately starts a new conversion after the last one finished, overwriting the previous result. If you pick it from the ADC result register directly or a memory location DMA transfers it to does not matter in this case.
Continuous conversion is useful when you read a channel at random intervals, and want a recent value.

DMA only saves you time and effort if you convert multiple channels. You usually have a sequence of channels / conversions, and want a DMA-TC interrupt when one sequence has finished.

Associate
January 21, 2025

@Ozone I do agree with this. But my actual issue is that the adc value output for continuous conversion is around 900-1000 even if change the input value from 0 to 3.3v.But for single conversion I'm getting the expected output. And my STMcubeIDE version is 1.16.1

Ozone
Principal
January 21, 2025

Could it be that your DMA is not working correctly, i.e. doing only one transfer and then stops ?
I don't use Cube/HAL, so I will not comment to related code.

Do you have an interrupt enabled in your scenario (e.g. DMA TC) ?