Idin Esmkhani
Idin Esmkhani

Reputation: 41

Read ADC using DMA in STM32

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.

Upvotes: 0

Views: 475

Answers (1)

pmacfarlane
pmacfarlane

Reputation: 4317

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
    }
}

Upvotes: 2

Related Questions