cancel
Showing results for 
Search instead for 
Did you mean: 

ADC on stm32f0

Posted on June 12, 2015 at 10:22

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? Thanks 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
)
{
INIT_adc();
ADC_StartOfConversion(ADC1);
// Wait until conversion completion
while
(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOSEQ) == RESET);
// Get the conversion value
//int CO2=0;
ADC_StopOfConversion(ADC1);
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 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 */
calibration=ADC_GetCalibrationFactor(ADC1);
/* 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 */
//ADC_StartOfConversion(ADC1);
}

#adc-stm32f0
2 REPLIES 2
raptorhal2
Lead
Posted on June 12, 2015 at 15:30

For starters, channel 1 is PA1. Compare code with the ADC Basic Example in the F0 Std Peripheral Library examples. I think you will find other errors as well.

Cheers, Hal

Posted on June 12, 2015 at 16:13

Thanks a lot! In fact I thought that channel was calling the channels already configured ( like pb0 in my case) 

You made my day!