cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 ADC read voltage value difference

GunkutA
Senior

Hello, I am uing STM32F103 MCU and I am having a small problem with the ADC. There is a 250 mV difference between the real voltage value on a pin and the value ADC gives me. When I measure the voltage on a pin it is 900 mV. But when I print out the ADC value it gives me a value 1150.

Here is how I configure and measure ADC:

int readVoltageValue (uint32_t channel){
 
	/**Configure Regular Channel
	 */
	ADC_ChannelConfTypeDef sConfig;
	sConfig.Channel = channel;
	sConfig.Rank = ADC_REGULAR_RANK_1;
	sConfig.SamplingTime = ADC_SAMPLETIME_7CYCLES_5;
	if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
	{
		//_Error_Handler(__FILE__, __LINE__);
	}
 
	HAL_ADC_Start(&hadc1);
	HAL_ADC_PollForConversion(&hadc1,1000);
	int adcValue = (int) HAL_ADC_GetValue(&hadc1);
	return adcValue;
}

And this is when I call the ADC function:

Vout=(readVoltageValue(ADC_CHANNEL_3));

Everything looks fine. Actually ADC is also working but like I said there is 250 mV difference. What might be the reason behind that?

1 REPLY 1
GunkutA
Senior

Edit: When there is 0V on the pin MCU reads it as 2V... Probably caused by Blue Pill STM32