cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L431VC rading ADC value from 1 channel on multichannel set up

DominykasS
Associate II

Hello,

I am using ADC1 channel 1, 3 and 5. All these three inputs are connected to different sensors and I want to create a driver to read those sensors. The problem is that I don't want to read all input channels at once, I want to be able to select which channel value to get. Also I want to use DMA and conversion complete interrupt. Is this possible?  Which mode should I use to be able to tell ADC1 which channel value to convert? I am using HAL library. Right now I enabled scan mode, so after running HAL_ADC_Start_DMA() I get all sensors data. 

1 ACCEPTED SOLUTION

Accepted Solutions

but it just seems weird that it is not possible to get analog value of just 1 channel when (for example) 16 channels are configured, it seems like an overkill to do all this conversion for just 1 channel.

This is how the ADC was designed to be able to do some advanced operations.  

Using Scan mode does not affect your application perf as the ADC is doing it automatically. Otherwise, you need to stop conversion/configure new channel/ start conversion but this would affect your application perf.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

8 REPLIES 8
SofLit
ST Employee

Hello,


Right now I enabled scan mode, so after running HAL_ADC_Start_DMA() I get all sensors data. 

Why Scan mode is not suitable for you? As you can read all the channels but at final you use the value you need.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
TDK
Guru

You can convert a single channel at a time. After conversion, stop the ADC and reconfigure it to convert the next channel. You will need to reconfigure it on every conversion.

Seems easier to convert all channels at the same time. What's the drawback there?

If you feel a post has answered your question, please click "Accept as Solution".

this seems like a bit of overkill. I need 1 channel data, but I read (for example) 16 channels. I just feels like there should be possibility to read just 1 channel at the certain time. 

Yeah it seems like this is the only way. For my case it doesn't really matter if I read 1 channel or all channels, because ADC reading is going to be used in DMA, but it just seems weird that it is not possible to get analog value of just 1 channel when (for example) 16 channels are configured, it seems like an overkill to do all this conversion for just 1 channel.


but it just seems weird that it is not possible to get analog value of just 1 channel when (for example) 16 channels are configured, it seems like an overkill to do all this conversion for just 1 channel.

This is how the ADC was designed to be able to do some advanced operations.  

Using Scan mode does not affect your application perf as the ADC is doing it automatically. Otherwise, you need to stop conversion/configure new channel/ start conversion but this would affect your application perf.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

> I just feels like there should be possibility to read just 1 channel at the certain time. 

It is possible. To do so, configure the ADC to convert a single channel before calling HAL_ADC_Start_DMA. This is a few lines of code.

If you feel a post has answered your question, please click "Accept as Solution".

but which channel will it convert? If, for example, I enable channel 3, 5, 9 on Cubemx? Can you give a short example? 

TDK
Guru

CubeMX is not set up to have multiple configurations for the ADC. You can implement the switching in user code.

If you feel a post has answered your question, please click "Accept as Solution".