2026-04-25 5:45 AM - edited 2026-04-25 5:47 AM
Good day,
I want to measure the VBAT voltage of a STM32WL31 using its ADC. I setup the ADC channel as follows using the ST HAL driver:
ADC_ChannelConfTypeDef ConfigChannel = {0};
ConfigChannel.Channel = ADC_CHANNEL_VBAT;
ConfigChannel.Rank = ADC_RANK_1;
ConfigChannel.VoltRange = ADC_VIN_RANGE_3V6;
ConfigChannel.CalibrationPoint.Number = ADC_CALIB_POINT_1;
ConfigChannel.CalibrationPoint.Gain = LL_ADC_GET_CALIB_GAIN_FOR_VINMX_3V6();
ConfigChannel.CalibrationPoint.Offset = LL_ADC_GET_CALIB_OFFSET_FOR_VINMX_3V6();
if (HAL_ADC_ConfigChannel(&hadc1, &ConfigChannel) != HAL_OK)
{
Error_Handler();
}I seem to be getting correct ADC measurements (actual=3.0V, adc_measured_&_converted=3.15V), but the detail seems to be sparsely documented in the device datasheet and manual, so I just want to check a few things:
Q1: I am not sure how the calibration point number relates to the measurement - when would one use ADC_CALIB_POINT_2 etc?
Q2: What is the reference voltage used by the ADC? The manual mentions VDDA, which would not make sense measuring VBAT (as they are the same voltage). The ADC reference seems to be 1.2V - is this the internal bandgap voltage also used by the comparator? And what is its voltage tolerance typically?
Q3: As VBAT is defined to be on a negative single ended channel, I'm assuming the raw measurement decreases as VBAT voltage increases? So in order to convert to voltage, it seems:
Thank you.