2025-11-26 6:55 AM - edited 2025-11-26 7:00 AM
I'm trying to implement the ADC to get V_BAT. I've done the set up in CubeMX in the IDE.
I then went to the examples to see how a single ADC reading was done. I'm confused about the use of the following variables...
/* Variables for ADC conversion data */
__IO uint16_t uhADCxConvertedData = VAR_CONVERTED_DATA_INIT_VALUE; /* ADC group regular conversion data */
/* Variables for ADC conversion data computation to physical values */
uint16_t uhADCxConvertedData_Voltage_mVolt = 0; /* Value of voltage calculated from ADC conversion data (unit: mV) */
/* Variable to report status of ADC group regular unitary conversion */
/* 0: ADC group regular unitary conversion is not completed */
/* 1: ADC group regular unitary conversion is completed */
/* 2: ADC group regular unitary conversion has not been started yet */
/* (initial state) */
__IO uint8_t ubAdcGrpRegularUnitaryConvStatus = 2; /* Variable set into ADC interruption callback */
In the rest of the example code these are used as if they were reading & writing directly from & to the ADC registers,
while (1)
{
/* Reset status variable of ADC group regular unitary conversion before */
/* performing a new ADC group regular conversion start. */
ubAdcGrpRegularUnitaryConvStatus = 0;
/* Init variable containing ADC conversion data */
uhADCxConvertedData = VAR_CONVERTED_DATA_INIT_VALUE;
/*## Start ADC conversions ###############################################*/
/* Start ADC group regular conversion with IT */
if (HAL_ADC_Start_IT(&hadc1) != HAL_OK)
{
/* ADC conversion start error */
Error_Handler();
}
/* Wait till conversion is done */
while (ubAdcGrpRegularUnitaryConvStatus == 0);
/* Note: ADC conversions data are stored into variable */
/* "uhADCxConvertedData". */
}
Yet I cant find anywhere in the code where these links are made. Can someone explain to me what's going on here?
2025-11-26 7:01 AM
This uses interrupts.
The interrupt ADC1_IRQHandler is called here:
Which calls the HAL handler, which calls HAL_ADC_ConvCpltCallback here:
the reading of the ADC register is done here: