2022-04-06 08:22 AM
Hi,
can anyone please provide help/sample/tutorial on how to read two different ADC Pins on my STM32L031F6 using STM32CubeIDE, idealy without DMA, but with would also work.
I have two analog signals on PA2 and PA3 and would like to read them. I suppose this are CHANNEL_2 and CHANNEL_3. I tried to follow different tutorials but the important settings are not available in my IDE (Scan Conversion Mode, Number of Conversions, ...).
I suppose it is a configuration issue, because when performing the classical HAL_ADC_PollForConversion and HAL_ADC_GetValue it either returns always 0 or always the same Value for all channels (seems to be the first one).
Any hints?
Regards, Durpex
2022-04-06 11:37 AM
Show your code or try some eamples from C:\Users\......\STM32Cube\Repository\STM32Cube_FW_L0_V1.12.0\Projects\NUCLEO-L031K6\Examples\ADC\
2022-04-06 12:26 PM
Hello @durpex and welcome to the STM32 Community :)
You can refer to this post Multiple ADC channels on STM32L072xx.
When your question is answered, please close this topic by choosing Select as Best. This will help other users find that answer faster.
Imen
2022-04-06 02:15 PM
If timing is not of paramount importance, one of the simplest way to achieve this is to start a single conversion on one channel, poll until done, read value, switch channel, start single conversion, poll until done, read value, rinse and repeat.
Funnily enough, while this is almost trivial to write using the normal programming methods, it may be hard to click out in Cube, as this is not a "usual usage mode" as envisaged by Cube authors.
JW
2024-02-15 12:35 AM
The thing is that we have to carefully read the documentation for our devices :) Let me quote some piece of it:
"uint32_t ADC_InitTypeDef::ScanConvMode
Configure the sequencer of regular group. This parameter can be associated to parameter
'DiscontinuousConvMode' to have main sequence subdivided in successive parts. Sequencer is
automatically enabled if several channels are set (sequencer cannot be disabled, as it can be the case
on other STM32 devices): If only 1 channel is set: Conversion is performed in single mode. If several
channels are set: Conversions are performed in sequence mode (ranks defined by each channel number:
channel 0 fixed on rank 0, channel 1 fixed on rank1, ...). Scan direction can be set to forward (from
channel 0 to channel 18) or backward (from channel 18 to channel 0). This parameter can be a value of
ADC_Scan_mode"
So in a few words, if multiple channels selected - scan mode is enabled by default, and the rank is defined by the number of ADC channel.
Cheers!