2012-06-09 12:53 PM
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);2012-06-09 04:44 PM
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, Hal2012-06-10 07:48 AM
Thanks for the advice but it did not resolve the issue. Any other ideas guys?
2012-06-11 07:03 AM
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, Hal2013-01-22 04:18 AM
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.
2014-03-20 09:22 AM
..\main.c(125): error: #20: identifier ''ADC1_IRQn'' is undefined
2014-03-20 09:30 AM
Likely missing a #include some where. Review the TEMPLATE projects supplied in the Firmware Libraries for the tool chain you are using.