cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F303 Vbat monitoring

Jerry Lin
Associate II

Hi everyone

I'm trying to use STM32F303 to measure the battery voltage via Vbat pin.

I use 1-cell Li-Po battery (about 3.5V to 4.2V)​

According to the datasheet the Vbat should be 1.65V to 3.6V

So I have a 3/4 voltage divider resistor outside the chip, and according to the datasheet there is a another 1/2 voltage divider inside the chip when vbat monitoring is on.

Here is my setting and the code.0693W000003QrLBQA0.png0693W000003QrLaQAK.png

0693W000003QrLfQAK.png

When the battery is at 4.2V the value should be 4.2 * ( 3 / 4 ) * ( 1 / 2 ) / 3.3 * 1024 = 489

But I only got 470.

When the battery is at 3.6V the value should be 3.6 * ( 3 / 4 ) * ( 1 / 2 ) / 3.3 * 1024 = 418

But I only got 400.

I'm not sure where I set it wrong.

And another question is that what is the proper sample time for this problem.

3 REPLIES 3
TDK
Guru

So you have a 4% error. Is your VDDA voltage exactly 3.3V? How accurate are your 4.2V and 3.6V sources? How accurate are the resistors in your voltage divider? Lots of potential sources for error can add up.

The sample time requirement is given in the datasheet. The number of cycles will depend on the ADC clock.

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

I'm confused by this:

0693W000003QrNqQAK.png

Is your battery actually attached to VCC? So you're not actually using the VBAT pin for anything other than its ADC capability?

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

Thanks for the reply.

I use external voltage-adjustable DC regulator for test run, so the input is guaranteed.

And I check the R4/R5 divider voltage.

For 4V input I got 2.97V, so the error here is about 1%.

I not sure where is the other 3% come from.

I attached battery to VCC and through the R4/R5 divider to vbat pin.

I also have 2 regulator on board for 3.3V and 3.3VADC.