Showing results for 
Search instead for 
Did you mean: 

STM32 ADC values reading too high

Posted on July 17, 2014 at 02:32

I am using an STM3240G-EVAL board to read in values from the ADC. I print the values from the ADC to the LCD on my board using the print function below. I physically connected the temperature sensor to 3.3V, ADC3, and GND on the eval board. The values that are being returned are too large. The ADC Resolution is supposed to be 12 bit so 4096 should be the maximum value output by the ADC_GetConversionValue function. I am receiving 5000+ values at room temperature! Does anyone have any intuition as to why the ADC values could be getting scaled?

////// stm324xg_eval.c

// to configure the ADC

void STM_EVAL_TEMPInit(Temp_TypeDef Temp)



RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE);

/* Enable the GPIO_TEMP Clock */


/* Configure the GPIO_TEMP pin */

GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitStructure.GPIO_Pin = GPIO_TEMP_PIN[Temp];

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIO_TEMP_PORT[Temp], &GPIO_InitStructure);

/* Enable ADC3 Clock */

ADC_InitTypeDef ADC_InitStructure;

ADC_CommonInitTypeDef ADC_CommonInitStructure;

ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;

ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4;

ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;

ADC_CommonInitStructure.ADC_TwoSamplingDelay = 0;


ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

ADC_InitStructure.ADC_ScanConvMode = DISABLE;

ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_Init(ADC3, &ADC_InitStructure);

ADC_RegularChannelConfig(ADC3, ADC_Channel_4, 1, ADC_SampleTime_144Cycles);



////// main.cpp// to print to lcd


temp_value = ADC_GetConversionValue(ADC3);

uint8_t mymsg[20];

sprintf((char *)mymsg, ''ADC = %d'',(int)temp_value);

LCD_DisplayStringLine(Line6, mymsg);

////// stm32f4xx_adc.c

// ADC_GetConversionValue function

/*** @brief Returns the last ADCx conversion result data for

regular channel.* @param ADCx: where x can be 1, 2 or 3 to

select the ADC peripheral.* @retval The Data conversion value.*/

uint16_t ADC_GetConversionValue(ADC_TypeDef* ADCx)


/* Check the parameters */


/* Return the selected ADC conversion value */

return (uint16_t) ADCx->DR;


#embedded #stm3240g-eval #adc

Posted on July 17, 2014 at 04:03

That's pretty much unreadable. Use the Format Code Block tool (Paintbrush [<>] icon)

Use a separator like printf(''<%d>'',sample)

Wait for a conversion complete signal, and make sure to clear or completely initialize any configuration structures.

Copy samples into an array, and then look at them with a debugger.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on July 17, 2014 at 15:05

The library example you adapted is missing a structure initialization. Add the following:

ADC_InitStructure.ADC_ExternalTrigConv = 0;

Cheers Hal