Skip to main content
Visitor II
June 3, 2024
Solved

STM32L4 Vbat ADC measurement incorrect

  • June 3, 2024
  • 1 reply
  • 1261 views

I'm using Vbat as a battery voltage monitor on an STM32L431.  Vref is the VDDA pin on this part, which is 3.3V.  In my test case, Vbat is also connected to the same 3.3V.

Vbat reads a raw count of around 1044.  The internal divider is /3, so this comes out to 3132 counts, which on a 12 bit ADC with a 3.3V ref comes out to 2.52V.  This is with a 3.3V input to the Vbat pin.  So, my technical term for that is "not even remotely close".

The ADC is set for 640 cycles conversion time (so it's not running too fast), it is calibrated, the Vref measurement is correctly reporting the 3.3V, another external channel reading a test voltage correctly.

I have confirmed through the debugger that VBATEN is set (it is actually CH18SEL on the L4, the HAL uses the VBATEN naming but it is the same bit), so the divider is enabled and connected to the ADC.

 

What else could be wrong?

 

 

 

    This topic has been closed for replies.
    Best answer by JBill.10

    Problem found between seat and keyboard!

    I was overriding my ADC channel config.  In the main init, I had the correct sampling time set.  Then in the set up code for the measurement, I overwrote that sampling time with the minimum.

    1 reply

    JBill.10AuthorAnswer
    Visitor II
    June 3, 2024

    Problem found between seat and keyboard!

    I was overriding my ADC channel config.  In the main init, I had the correct sampling time set.  Then in the set up code for the measurement, I overwrote that sampling time with the minimum.