cancel
Showing results for 
Search instead for 
Did you mean: 

ADC regular channel not ready after enabling ADC

bluscape
Associate III
Posted on June 09, 2012 at 21:53

I'm trying to use a single ADC channel on a STM32L151 using Keil Realview and ST libraries.

After enabling the ADC I wait until the ADONS bit is set indicating the ADC is ready to convert but it does not set. Looking at the ADC_SR I realized that the RCNR (Regular channel not ready) bit is set. I'm not sure how to resolve this. Below is my ADC initialization code.

    ADC_InitTypeDef ADC_InitStructure;

    NVIC_InitTypeDef NVIC_InitStructure;

    GPIO_InitTypeDef GPIO_InitStructure;

    

    /* ADC1 DeInit */  

    ADC_DeInit(ADC1);

    

    GPIO_InitStructure.GPIO_Pin = SMPS_FEEDBACK_PIN;

      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_Resolution = ADC_Resolution_12b;

    ADC_InitStructure.ADC_ScanConvMode = DISABLE;

    ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConvEdge_None;

    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

    ADC_InitStructure.ADC_NbrOfConversion = 1;

    ADC_Init(ADC1, &ADC_InitStructure);

    

    //ADC_DiscModeCmd(ADC1, ENABLE);

    //ADC_DiscModeChannelCountConfig(ADC1, 1);

    //ADC_EOCOnEachRegularChannelCmd(ADC1, ENABLE);

    /* ADC1 regular channel1 configuration */

    ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_48Cycles);

    

    NVIC_InitStructure.NVIC_IRQChannel = ADC1_IRQn;

      NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

      NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

      NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

      NVIC_Init(&NVIC_InitStructure);

    

    // Enable the adc interrupt

    ADC_ITConfig (ADC1, ADC_IT_EOC, ENABLE);

 

    /* Enable ADC1 */

    ADC_Cmd(ADC1, ENABLE);

    /* Wait until the ADC1 is ready */

    while(ADC_GetFlagStatus(ADC1, ADC_FLAG_ADONS) == RESET)

    {

    }

    /* Start ADC1 Software Conversion */

    ADC_SoftwareStartConv(ADC1);
6 REPLIES 6
raptorhal2
Lead
Posted on June 10, 2012 at 01:44

Some ST Library examples omit a 7th ADC_Init structure member that can cause grief if not initialized:

    ADC_InitStructure.ADC_ExternalTrigConv = 0;

Also, try enabling Scan Conversion Mode

 ADC_InitStructure.ADC_ScanConvMode = ENABLE;

Cheers, Hal

bluscape
Associate III
Posted on June 10, 2012 at 16:48

Thanks for the advice but it did not resolve the issue. Any other ideas guys?

raptorhal2
Lead
Posted on June 11, 2012 at 16:03

I don't have an L1 to try your code on, but in comparing it to the ADC1_IDDmeas Library example, the example enables continuous conversion mode also, and doesn't set the GPIO pin to no pull. Setting the pin to AN should suffice.

Cheers, Hal

karlp
Associate II
Posted on January 22, 2013 at 13:18

I was having exactly this problem.  The cause was HSI not being turned on.  I was running straight after boot, and was still running from the MSI.  Because the L1 uses HSI always for ADC, instead of some division of hCLK, this was stalling when I hadn't turned on the HSI.

haythem
Associate II
Posted on March 20, 2014 at 17:22

..\main.c(125): error:  #20: identifier ''ADC1_IRQn'' is undefined

Posted on March 20, 2014 at 17:30

Likely missing a #include some where. Review the TEMPLATE projects supplied in the Firmware Libraries for the tool chain you are using.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..