AnsweredAssumed Answered

Select ADC channel to convert

Question asked by massimi.federico.001 on Apr 30, 2018

hi, I have a problem using an ADC of a STM32L476.
In my project I have to sample 5 analogue channels with an ADC. I've configured everything with STM32CubeMX and want to use it in polling mode.
I have seen examples where this code is:

HAL_ADC_Start(&hadc);
if (HAL_ADC_PollForConversion(&hadc, HAL_MAX_DELAY) == HAL_OK) {
        ADC_ch0_value = HAL_ADC_GetValue(&hadc);
        HAL_ADC_PollForConversion(&hadc, HAL_MAX_DELAY);
        ADC_ch1_value = HAL_ADC_GetValue(&hadc);
        HAL_ADC_PollForConversion(&hadc, HAL_MAX_DELAY);
        ADC_ch2_value = HAL_ADC_GetValue(&hadc);
        ...
         ...
}                              
HAL_ADC_Stop(&hadc);

in which the channels are converted sequentially, what I would like to do instead is to convert only the selected channel, for example:

HAL_ADC_Start(&hadc);
---> SELECT ADC CHANNEL 3 <---
if (HAL_ADC_PollForConversion(&hadc, HAL_MAX_DELAY) == HAL_OK) {
        ADC_ch3_value = HAL_ADC_GetValue(&hadc);
}                              
HAL_ADC_Stop(&hadc);

// other code
// other function

HAL_ADC_Start(&hadc);
---> SELECT ADC CHANNEL 1 <---
if (HAL_ADC_PollForConversion(&hadc, HAL_MAX_DELAY) == HAL_OK) {
        ADC_ch1_value = HAL_ADC_GetValue(&hadc);
}                              
HAL_ADC_Stop(&hadc);

what I do not know how to do is the code for: 

---> SELECT ADC CHANNEL n <---

How can I do? can someone help me?

Outcomes