Skip to main content
RMatv
Associate
March 18, 2019
Question

What is the right way to read several ADC channels in autonomous way?

  • March 18, 2019
  • 1 reply
  • 2118 views

I have a STM32L011-Nucleo board, and I'd like to make a simple code to read two ADC channels independent to the main code (interrupt or DMA mode).

HAL library is a bit confusing for me so I'd be glas to see the right set of functions to use.

So first I need to set up ADC and DMA in STM32CubeMX which looks straight forward.

After that I need to initialize the variable to store the data from ADC:

uint16_t ADCres[2];

After that I should run ADC in DMA mode:

HAL_ADC_Start_DMA(&hadc, ADCres, 2);

That is it? Can I just read the ADCre[0] and ADCres[1] variables after that to have the very last measures?

In some tutorials there was HAL_ADC_ConvCpltCallbach function which looks not really necessary for me (in tutorials they just copied the values from one place to another after the ADC cicle ended).

This topic has been closed for replies.

1 reply

S.Ma
Principal
March 18, 2019

Do you want the conversion to run continuously?

Do you want the conversion sequence of 2 channels to be triggered by a signal (for example to control the sampling rate)?

If you run continuously without trigger, the DMA will fill and refill your ADCres array, just read the "freshest values" from the main loop if this is sufficient.

RMatv
RMatvAuthor
Associate
March 18, 2019

I want the conversion to run continuously. So after ADC will complete conversion of two channels, I'd like ADC to start from the first channel again and overrun the old value in ADCres[0] as the new conversion will be finished. And so on.

I want to start the conversion once in the code and not bother again.

So after reading your last sentence I feel that my assuptions were right?