I want to read ADC1 and ADC2 on an STM32 using DMA. I use ADC callback as shown below:
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
}
How can I make a decision between ADC1 and ADC2?
For example, I want to update Val_1
after ADC1 conversion is done and update Val_2
after ADC2 conversion is done.
The ADC_HandleTypeDef* hadc
passed into your callback function has an Instance
field you can check. e.g.
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
if (hadc->Instance == ADC1)
{
// ADC1 code
}
else if (hadc->Instance == ADC2)
{
// ADC2 code
}
}