STM32F103C8T6 Reference Voltage READ

Post here first, or if you can't find a relevant section!
hyur
Posts: 36
Joined: Fri May 27, 2022 7:42 am
Answers: 2

Re: STM32F103C8T6 Reference Voltage READ

Post by hyur »

ag123 wrote: Thu Jun 02, 2022 4:19 am google search for RM0008 stm32f103
you should get this
https://www.st.com/resource/en/referenc ... ronics.pdf

look in the chapter for ADC, look under temperature sensor section
in libmaple (roger's core) you may need to use the adc library or rather the adc includes in the core for that.
Following your advice, I checked the register and was able to read the internal temperature value as well.

I got the Vsense value through analogRead, and checked the internal temperature according to the following formula.
{(V25 - VSENSE) / Avg_Slope} + 25.

However, the formula related to Vrefint could not be found in the datasheet.

Is there something I'm missing out on?
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: STM32F103C8T6 Reference Voltage READ

Post by ag123 »

Vrefint is in the data sheet
https://www.st.com/en/microcontrollers- ... 103c8.html

5.3.4 Embedded reference voltage
VREFINT min 1.16, typ 1.2 max 1.24 v
that is the adc reading you get for 1.2v

so assuming a linear range, and that the top is vdd 3.3v
by linear projection : adc reading at vdd = 3.3 * adc_value / 1.2
that is the value at the top
it should be pretty close to 4096 ~ 2^12 for 12 bits adc

if I'm not too fussy about accuracy, I'd make a wild assumption 3.3v reads as 4096
so my voltage at adc reading : adc_volt = adc_value * 3.3 / 4096
otherwise you could substitute this 4096 with the adc reading at vdd found from the prior step using Vrefint
hyur
Posts: 36
Joined: Fri May 27, 2022 7:42 am
Answers: 2

Re: STM32F103C8T6 Reference Voltage READ

Post by hyur »

Following your advice, I was able to read the datasheet and read the ADC1_IN17(Vrefint) value.

With Vrefint and the following formula, I was able to get a value of 3.27~3.28V.
float VRef = (1.20 / vrefint) * 4096.0;

I measured the voltage on the board and it came out 3.314V. Is this an acceptable errors?

If so, is the sampling time an issue?
Right now my sampling timing is set to 71.5 cycles.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: STM32F103C8T6 Reference Voltage READ

Post by ag123 »

your formula looks right, the adc won't get the full 3.3v at the top in part due to the various electronics (e.g. transistors in there)
being a little less than 3.3v looks normal.
As things I do normally won't need very high precision or accuracy, i'd make do
other ways you could verify things is to measure a known voltage on the adc, e.g. compare with a multimeter etc
that'd let you know if you are on the right track.
hyur
Posts: 36
Joined: Fri May 27, 2022 7:42 am
Answers: 2

Re: STM32F103C8T6 Reference Voltage READ

Post by hyur »

As a result of measuring in millimeters, I was able to read a value similar to the internal reference voltage.

Thanks to you, I was able to solve my difficulties.

Thank you very much.
john1995
Posts: 1
Joined: Wed Aug 30, 2023 11:42 am

Re: STM32F103C8T6 Reference Voltage READ

Post by john1995 »

hyur wrote: Fri Jun 03, 2022 8:23 am Following your advice, I was able to read the datasheet and read the ADC1_IN17(Vrefint) value.

With Vrefint and the following formula, I was able to get a value of 3.27~3.28V.
float VRef = (1.20 / vrefint) * 4096.0;

I measured the voltage on the board and it came out 3.314V. Is this an acceptable errors?

If so, is the sampling time an issue?
Right now my sampling timing is set to 71.5 cycles.
what value has the variable vrefint?
Post Reply

Return to “General discussion”