Skip to main content
Visitor II
November 14, 2018
Question

How to read multiple ADC channel on STM32L011 ?

  • November 14, 2018
  • 1 reply
  • 747 views

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

    This topic has been closed for replies.

    1 reply

    Visitor II
    July 21, 2024

    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) );