Showing results for 
Search instead for 
Did you mean: 

STM32F070RB ADC reading from multiple channels

Associate III

Hi everyone!!

My MCU has only one ADC but I would like to read values from two analog sensors. Which is the best way to do so?

Thank you!!!!


That ADC contains an input multiplexer, which can switch between several input pins, so you can convert voltages from several input pins consecutively.

Read the ADC chapter in RM.


Chief II

If you need ADC two sensors in one moment , this cant. But some micro seconds ... no problem.

Thank you for your answer 🙂

Let's assume I have only 2 channels and I want to scan CH1 every second and CH2 every 100ms. To do so I use a timer but how can I manage the multiplexer to read from CH1 or CH2? I mean.. which is the ADC fuction that allows me to tell the multiplexer which channel to read from?


Scan CH1 and CH2 at 100 ms and save every CH2 and every 10th CH1.


Start simple, configure the adc dma to scan both channels continuously at 500kHz (the real speed depends on adc clock and sample and hold time) Then when you need to get the fresh sensor values, read the 2 ram location anytime or timebased.

Bruteforce for proof of concept. Later, if low power needed, use timer to trigger the conversion of both chanmels when needed.

Associate II

hello best thing u can do is to use dma and timer and adc at the same time this way u can read adc without make cpu busy (dma take the value from RDR registry and put it in a string every time the timer update event or CNT match the ARR in timer and the hole process is gonna to be with out make ur cpu busy ) and at the end u can sprade ur resualt with a for loop)

things u need to do :

1- use a timer and if u wanna read both adcs every 100ms set it to 50 ms so its read 50ms one channel then w8 for next 50ms to read other channel )

1.1-make sure u turn on update event in timer for trigering event

2-use adc in scan conversion mode and not continius mode

2.1-turn on the external convertion mode and set it to ur timer event update

2.2-connect the dma with adc

3-declear a string so dma puts the data in it

4-turn on ur timer as normal not in intrupt mode

5-turn on ur adc in dma mode

now when first 50 ms arrive timer trigger adc and adc read channel1 then dma take the adc read and put it in ur string

when the second 50ms arrive again this process happend but on adc channel2

when dma transfer the amount that u told it to, it will give u an intruppt (if u want 10 reading (5reading each channel and take a avrage from them) then read or process the data it would take 500ms to dma intruppt u)

now with a simple for loop u can separate the data in the string, even string numbers is ur channel1s readings and odd string numbers is ur channel2s readings

now u use the main cpu just every time dma intruppts and u have more process power and its save power too .