Question
ADC regular channel not ready after enabling ADC
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);