4

Is there a function to read the Vrefint_cal in Cubes HAL libraries? I'm using the F3xx. I'd like to measure the supply voltage of the micro. The formula given in the reference manual is:

\$ \Large VDDA = 3.3V \times \frac{Vrefint_{cal}}{Vrefint_{data}} \$

I've been searching through HAL (cube) and couldn't find a method to return the Vrefint_cal. The datasheet says that it is at 0x1FFF F7BA - 0x1FFF F7BB, but I find it silly that there wouldn't be a method to read it directly.

Bence Kaulics
  • 6,353
  • 12
  • 33
  • 60
Tomas Svitil
  • 375
  • 4
  • 14

2 Answers2

5

One simple way is the following:

#define VREFINT_CAL_ADDR    0x1FFFF7BA

uint16_t vrefint_cal;                        // VREFINT calibration value
vrefint_cal= *((uint16_t*)VREFINT_CAL_ADDR); // read VREFINT_CAL_ADDR memory location

Or a more general is to simply create a pointer and assign 0x1FFFF7BA to it, and then the rest is the same.

Bence Kaulics
  • 6,353
  • 12
  • 33
  • 60
1
#define VREFINT_CAL_ADDR ((uint16_t*)((uint32_t)0x1FFFF7BA))

And then, for example:

Vdd = 3300*(*VREFINT_CAL_ADDR)/ADC_raw;

Where Vdd and ADC_raw are uint16_t.

More info here: https://letanphuc.net/2016/07/stm32f0-adc/

Pablo
  • 11
  • 1