This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

STM32F4 Discovery ADC continuous conversion single channel

Hi everybody, I've started to use the STM32F4 Discovery, now I'm trying to use the ADC as single channel in conitnuous mode without DMA, i doesn't work , is it posible to do it?


#include "stm32f4xx.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_adc.h"

//#include "GPIO_STM32F4xx.h"


ADC_InitTypeDef       ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
//DMA_InitTypeDef       DMA_InitStructure;
GPIO_InitTypeDef      GPIO_InitStructure;

uint16_t ADCLect=0;
uint16_t Counter=0;
uint16_t Done=0;

volatile uint32_t msTicks;                      /* counts 1ms timeTicks       */
FlagStatus Estado;
/*----------------------------------------------------------------------------
  SysTick_Handler
 *----------------------------------------------------------------------------*/
void SysTick_Handler(void) {
  msTicks++;
}
/*----------------------------------------------------------------------------
  delays number of tick Systicks (happens every 1 ms)
 *----------------------------------------------------------------------------*/
void Delay (uint32_t dlyTicks) {
  uint32_t curTicks;

  curTicks = msTicks;
  while ((msTicks - curTicks) < dlyTicks);
}

int main()
        {

                SystemCoreClockUpdate();

                if (SysTick_Config(SystemCoreClock / 1000)) { /* SysTick 1 msec interrupts  */
                        while (1);                                  /* Capture error              */
                }

                RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
                RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

                /* Configure PA1 in analog mode */

                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
                GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
                GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
                GPIO_Init(GPIOA, &GPIO_InitStructure);

                /* ADC Common configuration *************************************************/
                ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
                ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
                ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
                ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
                ADC_CommonInit(&ADC_CommonInitStructure);

                /* ADC1 regular channel 12 configuration ************************************/
                ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
                ADC_InitStructure.ADC_ScanConvMode = DISABLE;
                ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;//ENABLE;//DISABLE;
                ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
                ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
                ADC_InitStructure.ADC_NbrOfConversion = 1;
                ADC_Init(ADC1, &ADC_InitStructure);

                ADC_EOCOnEachRegularChannelCmd(ADC1,ENABLE);

                ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_3Cycles);
                ADC_ContinuousModeCmd(ADC1,ENABLE); // to make sure the CONT is set
                /* Enable ADC1 **************************************************************/
                ADC_Cmd(ADC1, ENABLE);
                ADC_SoftwareStartConv(ADC1);
                while (1)
                {
                        //ADC_SoftwareStartConv(ADC1);
                        Estado = ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC);
                        if(Estado){
                                Done=1;
                                ADCLect = ADC_GetConversionValue(ADC1);
                                //ADC_ClearFlag(ADC1,ADC_FLAG_EOC); // to clear the flags events.
                        }
                        Delay(100);
                }
                return 0;

}

when I use the ADC in mode discontinuous using the code below:

        ADC_SoftwareStartConv(ADC1);
        ADCLect = ADC_GetConversionValue(ADC1);
        ADC_ClearFlag(ADC1,ADC_FLAG_EOC);

it Works well.

I hope somebody can help me

  • Hi body,
    I have the same question!
    I use HAL-Driver.
    The function
    HAL_ADC_START_IT(&hadc1);
    is called and function
    HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
    is triggered for only one time and it does't work continues also ADC state have an Error after first conversion.
    How can I Solve this problem?
    Any Idea?
    Tnx...