Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
5 years, 3 months ago.
AnaloIn of VREF returns 0.361905
Hi every body!
I'm trying to learn mbed with help of Nucleo ST32F103RB.
And a very simple code:
AnalogIn aiVREF(ADC_VREF); pc.printf("internal VREF %f\r\n",aiVREF.read());
returns 0.361905
In my point of view it should return 1.0
Could someone explain what is wrong?
1 Answer
5 years, 2 months ago.
Hello Vladislav,
The reference voltage used by Mbed for AnalogIn
is VCC (= 3.3V). So it reads 1.0 when connected to VCC. According to chapter 5.3.4 Embedded reference voltage
of the STM32F103 datasheet the embedded reference voltage is typically 1.2V and that is consistent with the value returned by your program:
0.361905 * 3.3V ~ 1.2V
Thank you very much for clarification. I'm going to measure other values (lower than 3.3) via AnalogIn and can I rely on 3.3 vlaue for STM32F103? Is it hardcoded somewhere in board definition or driver?
PS. The next step is to get internal temp. I saw your code with direct HAL access. But it didn't go trough HAL_ADC_PollForConversion (always timeout). I'll try to do this via mbed tools.
posted by 25 Sep 2019Yes, when I can get VRef then I can calculate Internal Temp with help of this standard HAL macros: LL_ADC_CALC_TEMPERATURE_TYP_PARAMS
posted by 25 Sep 2019The AnalogIn API
is described here. I think it's up to the vendor of the given target board to take care that it works like that. This is usually achieved by providing an appropriate driver for ADC and/or by HW design (for example by connecting the Vref+ pin, if such is available on the package, to the given Mbed board's VCC bus). In case of an STM32F103RB (64-pin package) the Vref+ and Vref- pins are not available, they are internally connected to the ADC voltage supply (VDDA) and ground (VSSA) - as described in section 5.1.1 Independent A/D and D/A converter supply and reference voltage
of the RM0008 Reference Manual
.