2026-03-13 2:11 AM - last edited on 2026-03-13 2:52 AM by Andrew Neil
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.
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.
2026-03-13 5:36 AM
> custom PDB
What is the schematic?
> nome of them read correctly
What is the sampling time? Increase it to max.
2026-03-13 1:59 PM
This is the schematic:
I have changed the sampling time but I get 0x300 (0,675V) as battery level.
2026-03-18 12:20 AM
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?
2026-03-18 6:08 AM
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:
"calibrated gain of 1/3" doesn't make sense to me in this context.
2026-03-18 9:46 AM
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
2026-03-18 10:21 AM
Can you share your IOC file?
2026-03-19 11:59 PM
2026-03-23 2:37 AM
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.
2026-04-03 10:26 AM
Have you been able to check if it is configured correctly?