AnsweredAssumed Answered

ADC on stm32f0

Question asked by belloc.thomas on Jun 12, 2015
Latest reply on Jun 12, 2015 by belloc.thomas
Hi everyone,
I am currently working on developping an ADC on my stm32f051r8
In fact, the peripheral sends always incoherent values (550 for 0V, 500 for 3V sometimes for exemple). Working on the code this morning, I just realized that the flag ADRDY is never set after my configuration. 
Can you please help me?

EDIT: in fact the flag ADRDY was not set because of the auto-off mode.
But I still don't understand the values..
#include "stm32f0xx_adc.h"
#include "stm32f0xx_gpio.h"
#include "stm32f0xx_rcc.h"
void main(void)
     // Wait until conversion completion
      while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOSEQ) == RESET);
          // Get the conversion value
    //int CO2=0;
    unsigned int temperature= ADC_GetConversionValue(ADC1);
void INIT_adc (void)
    int calibration;
ADC_InitTypeDef          ADC_InitStructure;
        GPIO_InitTypeDef         GPIO_InitStructure;
      /* GPIOB Periph clock enable */
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
      /* ADC1 Periph clock enable */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
      /* Configure ADC Channel11 as analog input */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
        GPIO_Init(GPIOC, &GPIO_InitStructure);
      /* ADC1 Configuration *******************************************************/
      /* Configure the ADC1 in continous mode with a resolutuion equal to 8 bits*/
        ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
        ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
        ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
        ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_TRGO;
        ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
        ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward;
        ADC_Init(ADC1, &ADC_InitStructure);
      /* Convert the ADC1 Channel 11 with 239.5 Cycles as sampling time */
        ADC_ChannelConfig(ADC1, ADC_Channel_1 , ADC_SampleTime_28_5Cycles);
        //ADC_ChannelConfig(ADC1, ADC_Channel_2 , ADC_SampleTime_28_5Cycles);
      /* ADC Calibration */
      /* Enable the auto delay feature */
        ADC_WaitModeCmd(ADC1, ENABLE);
      /* Enable the Auto power off mode */
        ADC_AutoPowerOffCmd(ADC1, ENABLE);
      /* Enable ADCperipheral[PerIdx] */
        ADC_Cmd(ADC1, ENABLE);
      /* Wait the ADCEN falg */
      while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADRDY)){};
      /* ADC1 regular Software Start Conv */