cancel
Showing results for 
Search instead for 
Did you mean: 

How to read multiple ADC channel on STM32L011 ?

antonius
Senior

Dear STM32 Members,

How can I read multiple ADC channel on STM32L011 ?

I want to read channel 1,3,5,7?

How can I define it on STM32CubeMx

I can see HAL_ADC_Read, how can I read HAL_ADC(1),(3),(5),(7), what variable is being used ?

Is it an array ?

Thanks

1 REPLY 1
smj320
Associate

It looks like the ADC only has one conversion result register. Therefore, it is necessary to save the results using DMA or to switch channels and sample each time.

To switch only channels in a single-shot environment created with CubeMX, write the desired channel first in the SQR1 register, and write the sampling period of the desired channel in the SMPRx register.

 

For example, to specify channel 2 and reconvert, run the following code before converting.

 

WRITE_REG(hadc->Instance->SMPR1,ADC_SMPR1(ADC_SAMPLETIME_601CYCLES_5, 2) );
WRITE_REG(hadc->Instance->SQR1, ADC_SQR1_RK(2,1) );