cancel
Showing results for 
Search instead for 
Did you mean: 

adc continuous conversion with DMA for stm32f407G

AiswaryaLakshmi
Associate

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;

5 REPLIES 5
Mahmoud Ben Romdhane
ST Employee

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

 

Ozone
Lead II

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.

@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

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) ?

Hello @AiswaryaLakshmi ,

 

Further to your comment, I suggest that you take a look at this example "ADC_RegularConversion_DMA" provided on STM32CubeMX. It explains how to use the ADC1 and DMA to transfer continuously data from ADC1 to memory.

MahmoudBenRomdhane_0-1737448872568.png

Moreover, you can consult this ST Wiki.

It demonstrates what ADC is and how to use it with DMA.

 

Thanks.

Mahmoud