Over 10 years we help companies reach their financial and branding goals. Engitech is a values-driven technology agency dedicated.



411 University St, Seattle, USA


+1 -800-456-478-23

Embedded MCU's Getting Started and Peripheral Coding STM32 MCU's STM32F1

ADC(Analog To Digital Converter) in STM32F103

Child Category


Imagine that we are building a robot or an interactive art piece. We might be interested in measuring temperature, distance to the nearest object, force, and acceleration, sound pressure level, brightness, or any other physical characteristics. The first step is to convert all these physical quantities into a voltage using a transducer. The world is analog in nature, so every quantity that we need to measure is measured by the transducer in an analog output. But our Computers, MCU, Processors are digital in nature, that is they can Understand only ‘1’ and ‘0’. Thus we need an interface that can convert analog values of the world into digital values so as to process them. Thus here comes the ADC(Analog to Digital converter)

“Analog Signals need to be processed correctly before they can be converted into digital form. This processinbg of Analog Signal is done by Signal Conditioning circuits”

Important Terms in ADC

Resolution of ADC: As said, ADC transforms an analog voltage to a binary number(series of 1’s &0’s) which is then represented as a Digital Number over our screens. The Number of Binary digits (1 &0) that represents the Digital Number determines the ADC Resolution

ADC Introduction in STM32

Like every modern family of MCU, STM32 too has inbuilt ADC. Now if we open the datasheet of STM32F103 Bluepill and Navigate to its ADC Section.


Now let’s break down this ADC Introduction part to understand the ADC Peripheral in STM32 MCU

Successive Approximation: Type of ADC which is used in STM32 MCU.Which is made using OPAMPS, Resistors, Digital & Analog Electronic Circuit.
So depending upon the type of circuit their are different types of ADC.

1) Successive Approximation
2) Sigma Delta

3) Voltage to frequency
4)Dual Slope ADC

Analog Sensors & Electronics are huge topic, so wont be able to cover everything & would be focusing on STM32 MCU ADC Peripheral
Click Here12 Bit ADC : Resolution of the ADC Peripheral in STM32 MCUThis is Resolution of the ADC Peripheral in STM32 MCU.Means Decoded ADC value which we will get will be ranging from [0-4095] = 2^12Click Here18 Multiplexed Channels: Blue Pill we have 18 ADC pinsBasically channels means from which Analog Values of the External world/Transducer will be fed to the MCU.
Out of the 18 Pins Blue Pill has 16 external and 2 internal sources. This means that in 1) 16 pins [ADC0-15], we can fed analog values from the external world, like interfacing some analog sensors 2) 2 pins[ADC16:17] have the internal analog sources (Internal temperature Sensor & Internal Reference Voltage) : There is one inbuilt Temperature sensor inside the MCU which Outputs the data in analog value & send it to ADC_Channel 16.Click Here

So that is for the basic introduction of the ADC peripheral of STM32F103, now let\’s dive into more in-depth to know about the features of ADC peripheral in STM32 MCU.

ADC Features in STM32 MCU

Regular and Injected groups

In STM32 MCU ADC peripheral their is a feature of Regular and Injected Group, we can configure the ADC Channels to be either in Regular Group or Injected Group.
Regular Group: ADC Channels which are configured in regular group are converted regularly( when ADC peripheral is started by setting ADC_CR2:ADON bit), just like basic ADC conversion of channels one by one
Injected Group: Now Channels which are configured in injected group works on same principal of Regular Group but this group have higher priorty then Regular group. As it names says injected, this group will interrupt the Regular group Conversion

Click Here

Types of Conversion Modes in STM32 ADCTheir are 4 types of Channel Conversion Modes in STM32.
1) Single Conversion Mode
2) Continuous Conversion Mode
3) Scan Mode
4) Discontinuous ModeClick HereSingle Conversion Mode: As it name says \”Single Conversion\” so when ADC peripheral is configured to be in Single Conversion Mode , only one time conversion of configured ADC channels is done when ADC peripheral is triggered.Click HereContinous Conversion Mode:As it name says \”Continuous Conversion\”, so this is vice versa of single conversion. All the configured ADC channels are continuously converted once the ADC Peripheral is triggered by Software or by external event and converted data is continuously stored in ADC_DRClick HereScan Mode:This is 3rd type of Mode, as its name says\”Scan\”. So when configured in this mode, ADC works like a \”SCAN\”, it is used to scan a regular or injected group channel. In short, we can say if we are using more than 1 ADC channel & doing conversion of all configured ADC channels then we will be using Scan Mode. After the first channel conversion, it will go to the next configured channel for its conversion till the last channel configured
Click HereDiscontinous Mode:This is 4th type of mode, in this mode we can convert configured channels of regular and injected group in short sequences of n conversion (n<=8) on every external trigger. Click Here Previous Next

ADC Conversion Trigger

ADC conversion can be started by software or outside external hardware:
1) Software Trigger: A/D Conversion is started from Firmware for regular and injected group that is by setting the bit SWSTART(For Regular Group) and JSWSTART(For Injected Group) in ADC_CR2 register
2) Hardware Trigger: A/D Conversion is started when an external event (like Timer capture, EXTI line, etc) had occurred.

Click Here

Analog Watchdog

This is my personal favourite feature of ADC in STM32 MCU..
in this mode, we can set the upper and lower threshold at ADC_HTR & ADC_LTR register if ADC_DR falls below or above the configured threshold values, a status bit AWD in ADC_SR is set and interrupt can be generated if AWDIE bit is set in ADC_CR1 register. More in detail & practical implementation of this will be done in upcoming blog posts

Click Here

EOC(End of Channel) and JEOC(Injected End of Channel)

EoC and JEoC are the 2 bits in the ADC_SR register which tells us about the end of ADC conversion of a channel.
1) EoC: Whenever a group channel conversion (Regular or injected) is done, then this bit is set 2) JEoC: When all injected group channel conversion is done then this bit is set. So These 2 bits are basically the polling bits that will be used inside while to get to know when ADC Conversion has taken place

Click Here

DMA(Direct Memeory Controller)

DMA well this is a separate peripheral in its own, will not get into its inner details in this blog for DMA their will be another blog.
But just to give an overview DMA peripheral is used to do a transfer of data b/w memory without the intervention of CPU. So, if you remember their is a Brainfreeze i have stated in Continous Mode. DMA is used to transfer the ata which is stored in ADC_DR after conversion of 1 channel to the another memory( Probably at a memory of variable), then when another conversion takes place that is stored in another memory. By this ADC_Data register readings are not lost

Click Here



Leave a comment

Stay Updated With Us