cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 Vbat ADC measurement incorrect

JBill.10
Associate II

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?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
JBill.10
Associate II

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.

View solution in original post

1 REPLY 1
JBill.10
Associate II

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.