Skip to main content
DSimp.1
Associate III
April 14, 2022
Question

Trying to read VREFINT using STM32F103C8t6 (Blue pill) and getting wrong value.

  • April 14, 2022
  • 7 replies
  • 5221 views

Hey,

I'm trying to read VREFINT value using internal ADC channel for vrefint, I'm converting data from ADC to voltage and getting 1.34-1.38 V. Datasheet says it should be 1.2-1.24 V. Why my reading has such error ? I'm using 238.5 sampling time for 8 MHz ADC clock, here is data reading code :

void ADC_VAL () {

HAL_ADC_PollForConversion(&hadc1,1);

ADC_VAL=HAL_ADC_GetValue(&hadc1);

voltage = (ADC_VAL*3.3/4095);

}

This topic has been closed for replies.

7 replies

Michal Dudka
Lead
April 14, 2022

a) Your calculations are based on the 3.3V supply voltage. Are you sure that supply voltage is exactly 3.3V ?

b) Blue pill is often equiped with fake/clone STM chip and its internal reference does not have to be in specified limit.

c) ... some mistake in code (sampling time is not what you think etc.)

DSimp.1
DSimp.1Author
Associate III
April 14, 2022

I'm using ST_LINK to power mcu and it is 3.3V . It might be fake chip but I quite trust shop where i bought this board. And what about mistakes in code? Why sampling time is wrong?

Michal Dudka
Lead
April 14, 2022

I dont mean to say that your sampling time is wrong, but just mention that it can be also your software bug. Just take voltmeter and measure "blue pill" VDD (VREF+) to rule out a). To rule out b) take some another board with same chip, like discovery or nucleo board where you can be sure that chip is genuine. Run your program and look for results.

Peter BENSCH
ST Technical Moderator
April 14, 2022

Then you divide by 4095, presumably because you set the ADC to 12bit, right? But why 4095 if it is 12bit, i.e. 2^12=4096?

Furthermore, did you perform a calibration as recommended by RM0008 in section 11.4?

It is recommended to perform a calibration after each power-up.

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Michal Dudka
Lead
April 14, 2022

ad: "4095" vs "4096":

STM32F030x reference manual, page 205

https://www.st.com/resource/en/reference_manual/dm00091010-stm32f030x4-x6-x8-xc-and-stm32f070x6-xb-advanced-arm-based-32-bit-mcus-stmicroelectronics.pdf

VCHANNELx = VDDA / FULL_SCALE * ADC_DATAx

FULL_SCALE = 4095

and now what's right ... ?

TDK
April 14, 2022

It should be 4096, however that's well within the noise in this example.

0693W00000Ly00AQAR.png 

My guess is your VREF+ is not 3.3V or you haven't calibrated it after startup.

"If you feel a post has answered your question, please click ""Accept as Solution""."