AnsweredAssumed Answered

ADC initailization problem on STM32L series

Question asked by Luca85 on Mar 20, 2014
Latest reply on Mar 20, 2014 by Luca85
Hi,
I am trying to use ADC for reading the voltage on pin A4.. I wrote an initialization method, however it get stuck in the last WHILE.
Here there is the code:

void ADC_Initialize(void)
{
  ADC_InitTypeDef  ADC_InitStructure={};
  GPIO_InitTypeDef GPIO_InitStructure={};

        /* Enable GPIOA clock */
      RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
          /* Configure PA.4 (ADC Channel 4) in analog mode */
      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
      GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
      GPIO_Init(GPIOA, &GPIO_InitStructure);

        /* Enable ADC1 clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

        /* ADC1 configuration */
    ADC_InitStructure.ADC_ScanConvMode = DISABLE;
    ADC_InitStructure.ADC_ContinuousConvMode = 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);

    /* Enable ADC1 */
        ADC_Cmd(ADC1, ENABLE);

        /* Wait until the ADC1 is ready */
      while (ADC_GetFlagStatus(ADC1, ADC_FLAG_ADONS) == RESET);
}

Here some register values read in debug
Status register SR=256,
Control registers CR1=0 and CR2=1.

The problem is the bit ADONS (bit 6 of SR) that is never set.. and i get stuck inside the while...
Any idea why this happens?

Outcomes