cancel
Showing results for 
Search instead for 
Did you mean: 

STM32WB05KZ ADC Battery monitoring

Ruben_EMI
Associate II

I am using a STM32WB05KZ of a custom PDB, and I can not read a correct value of Vbattery.

I have programed the ACD (+DMA) usgin CubeMX.

Captura de pantalla 2026-03-13 100030.jpg

Captura de pantalla 2026-03-13 100106.jpg

  

 

I use DMA to read the analog inputs:

ADC_Conv_Cplt = 0;
HAL_ADC_Start_DMA(&hadc1, value, 3);
uint32_t start = HAL_GetTick();
while(ADC_Conv_Cplt==0){
  //timeout
  if ((HAL_GetTick() - start) > 3000){//wait 3 seconds
    break;
}
};

HAL_ADC_Stop_DMA(&hadc1);


According de manual, the formula for ADC converted data after calibration is the following: Code = Integer(4096/3.6 * VIN) [clamped at 4095]. The result of conversion from Vbat is 0x271, applying the formula I get 0,549V when the Vbat is 3V.

I also use 2 analog inputs in PB2 and PB5 and nome of them read correctly. In other proyects with stm32l105 and stm32wl55 the DMA works. I sure I am doing something wrong...

Can anybody help me?


Edited to apply proper source code formatting - please see How to insert source code for future reference.

10 REPLIES 10
TDK
Super User

custom PDB

What is the schematic?

> nome of them read correctly

What is the sampling time? Increase it to max.

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

This is the schematic:

Captura de pantalla 2026-03-13 215041.jpg

I have changed the sampling time but I get 0x300 (0,675V) as battery level.

Captura de pantalla 2026-03-13 215910.jpg

Ruben_EMI
Associate II

Any ideas?

In other MCU, Vbat is divided by 3, but in this case the reference manual do not mention it.

I have a doubt, I do not have a stable V refence, the device is supplied by batteru of 3V. I supose that the "voltage range" is used to select the V reference to ADC converter, in my case 2.4V, is it correct?

TDK
Super User

Not real sure.

In your original post you said:

> I get 0,549V when the Vbat is 3V

And then in the second post:

> I get 0x300 (0,675V) as battery level.

Why the difference? What has changed? I suspect there is a fixed divider but the math isn't working out.

 

Conversions are listed in the Reference Manual for the different ranges:

Screenshot 2026-03-18 090459.png

"calibrated gain of 1/3" doesn't make sense to me in this context.

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

Hi,

I was changed the sample rate from F_ADC_CLK /16 to F_ADC_CLK /28:

- F_ADC_CLK /16 I get 0,549V when the Vbat is 3V

- F_ADC_CLK /28 I get 0,675V when the Vbat is 3V

I don no use any calibration point

Captura de pantalla 2026-03-18 174409.jpg

TDK
Super User

Can you share your IOC file?

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

Yes, I have attached. Thanks.

Dobry
Associate II

Hello Ruben_EMI,

 

I am still getting familiar with the ADCs of the STM32 wireless series, but my practical observations so far are that when using "negative or minus" ADC input ports (I am see in VINM0 above), the measured value starts from 4095 and goes toward 0, i.e to get the "normal" value have to ectract measured from 4095, i.e.

adc_value = 4095 - adc_value;

Again, I am just starting with STM32W MCUs and I may be completely wrong, but it may worth to do few experiments at your setup and to confirm do you need to "inverse", the reading values or not...

 

Best Regards,

Dobry.

Have you been able to check if it is configured correctly?