2014-09-25 11:18 PM
Hello I have written a code refering to ADC example given in the peripheral library provided by ST.
I am using ADC in single conversion mode to measure the temperature. I will paste my code below. The problem is that code works in Debug Mode with break points at ADC code properly but in free running within debug or normal the ADC gives FFF as output. I am not understanding what is the issue, I tried adding delays within the ADC code but that didnot help. ADC Overrun keeps on happening. Even if EOC has occured the data is wrong ie FFF.//ADC Code
voidadc_init(
void){
ADC_InitTypeDef ADC_InitStructure; // GPIO_InitTypeDef GPIO_InitStructure; // TS_CAL1 = TS_CAL1_Address_High; // TS_CAL2 = TS_CAL1_Address_Low; /* GPIOC Periph clock enable */ // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, 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); /* ADCs DeInit */ ADC_DeInit(ADC1); /* Initialize ADC structure */ ADC_StructInit(&ADC_InitStructure); /* Configure the ADC1 in continuous mode with a resolution equal to 12 bits */ ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; 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_10 , ADC_SampleTime_239_5Cycles); ADC_ChannelConfig(ADC1, ADC_Channel_16 , ADC_SampleTime_239_5Cycles); ADC_TempSensorCmd(ENABLE); /* ADC Calibration */ ADC_GetCalibrationFactor(ADC1); /* Enable the ADC peripheral */ ADC_Cmd(ADC1, ENABLE); /* Wait the ADRDY flag */ while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADRDY));
/* ADC1 regular Software Start Conv */ // ADC_StartOfConversion(ADC1); } uint16_t get_adc_count( void) {
uint16_t adc_raw_data = 0; /* ADC1 regular Software Start Conv */ ADC_StartOfConversion(ADC1); /* Test EOC flag */ while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
/* Test EOC flag *//* Get ADC1 converted data */
adc_raw_data = ADC_GetConversionValue(ADC1); ADC_ClearFlag(ADC1, ADC_FLAG_EOC | ADC_FLAG_OVR); returnadc_raw_data;
} //Main Code reading of temperature temperature = ((V25 - get_adc_count())/AVG_SLOPE) + 25 ; //The get_adc_count returns 0xfff always #adc #dma #stm32f02014-09-26 09:25 AM
You seem to have started 3 threads on this topic, please don't do that.
Perhaps you want to check the ADC clock source, HSI14 or PCLK/2, or whatever. Do any of the other ADC examples work? Post a complete/concise example.