STM32 ADC Single Channel Polling Mode: Read a Potentiometer with CubeMX and HAL
Polling is the simplest way to read an analog input on an STM32. The firmware starts a conversion, waits for the end-of-conversion flag and reads the result, without any interrupt or DMA setup in between. This tutorial configures the ADC in single channel polling mode with STM32CubeMX and the HAL library, and the settings are shown for the STM32F103C8, the STM32F446RE and the STM32H750, so you can follow along with whichever board you have.
The STM32H750 development board is the main example, because its ADC offers the most features, including 16-bit resolution and a separate kernel clock. The changes needed for the STM32F103C8 Blue Pill and the STM32F446RE are described in their own sections. The code reads a potentiometer, maps the result to a range of 0 to 100 and checks the values in the STM32CubeIDE debugger.
This is part 1 of the STM32 ADC tutorial series. The next part shows single channel mode with interrupt and DMA, which frees the CPU while the conversion runs.
How STM32 ADC Polling Mode Works
In polling mode the CPU waits actively for the ADC to finish. The firmware starts a conversion, checks the end-of-conversion flag until it is set and then reads the digital value from the ADC data register.
Polling Sequence
The firmware follows the same four steps for every reading.
- Start the ADC conversion.
- Check the end-of-conversion flag repeatedly until it is set or a timeout expires.
- Read the ADC result from the data register.
- Continue with the rest of the program.
Because no interrupts or DMA are involved, the execution flow is easy to follow and to debug, which makes polling a good choice for learning examples and basic projects. The CPU is busy during the conversion, so the method is a poor fit for time-critical firmware or for programs that must do several jobs at once. A project with several parallel jobs is better built around an RTOS, as shown in the STM32 FreeRTOS tutorial.
STM32 ADC Features Across Boards
The configuration steps are similar across the STM32 families, but the ADC hardware differs. The table below compares the three devices used in this tutorial.
| STM32 series | Resolution | ADC clock source |
|---|---|---|
| STM32F103 | 12 bit, fixed | APB2 clock divided by a prescaler, with a maximum ADC clock of 14 MHz |
| STM32F446 | 6, 8, 10 or 12 bit | APB2 clock divided by a prescaler |
| STM32H750 | 8, 10, 12, 14 or 16 bit on ADC1 | Separate ADC kernel clock (PLL2P in this example) with its own prescaler |
The number of conversion cycles also depends on the series and the resolution, and the ADC conversion time tutorial lists the values and shows how to calculate the conversion time.
STM32F103 ADC Polling Setup
The STM32F103 setup in CubeMX consists of the clock, the ADC channel and a few conversion settings.
F103 Clock Configuration
The system runs from the external 8 MHz crystal, and the PLL raises the system clock to the maximum of 72 MHz. The ADC prescaler, set to 6 in the image, divides the APB2 clock down to an ADC clock of 12 MHz. The STM32F103C8T6 allows an ADC clock of up to 14 MHz, so 12 MHz is within the limit.
F103 ADC Channel and Mode
The example uses ADC1 channel 0, and CubeMX configures the pin PA0 as ADC1_IN0. The ADC works in independent mode, which means ADC1 runs on its own and does not need a second ADC.
F103 ADC Resolution
The ADC of the STM32F103C8T6 has a fixed resolution of 12 bit, and the resolution cannot be changed in CubeMX. The reference manual of the device confirms this.
F103 Data Alignment
The 12-bit result is stored in a 16-bit data register, and the data alignment decides whether the result is aligned to the left or to the right inside that register. The alignment is kept at Right, because the value can then be used directly without shifting it.
Scan Conversion Mode
Scan mode converts a group of channels in sequence. CubeMX enables it automatically when more than one channel is selected, and each channel of the group is converted once per scan. With continuous conversion enabled as well, the scan restarts from the first channel after the last one. This tutorial uses one channel, so scan mode stays disabled, and the multiple channels without DMA tutorial covers the scan case.
Continuous Conversion Mode
In continuous mode the ADC starts a new conversion as soon as the previous one has finished, and with a single channel the same channel is converted again and again. Polling mode starts each conversion manually from the code, so continuous mode stays disabled.
Regular and Injected Conversion
Regular conversion is the normal ADC mode. Injected conversion allows a sequence with a higher priority to interrupt the regular sequence, after which the regular sequence continues. This tutorial uses regular conversion only, and the injected conversion tutorial covers the other case.
External Trigger Source
The trigger source defines what starts a conversion. A timer output can be used as the trigger, which also controls the conversion rate. For polling the trigger is set to software, so the code starts each conversion when it is needed, and the external trigger tutorial shows the timer-based alternative.
Rank and Sampling Time
The rank section configures each channel. With several channels it also sets the order of the conversions, and for each channel it sets the sampling time in ADC cycles. A higher number of cycles gives the ADC more time to sample the input and increases the total conversion time. The example uses the maximum sampling time, because a potentiometer is a slow signal and speed is not a requirement. The formula behind this setting is explained in the ADC conversion time tutorial.
STM32F446 ADC Polling Setup
F446 Clock Configuration
The system runs from the external 8 MHz crystal, and the PLL raises the system clock to the maximum of 180 MHz. The clock configuration shows no separate ADC clock, because ADC1 is connected to the APB2 bus, as the block diagram in the datasheet shows. In this configuration the APB2 clock runs at 90 MHz.
F446 ADC Channel and Prescaler
The example uses ADC1 channel 0 with PA0 as the ADC1_IN0 pin, and the ADC works in independent mode. The ADC clock prescaler divides the APB2 clock, and a prescaler of 6 reduces the 90 MHz clock to an ADC clock of 90 / 6 = 15 MHz.
F446 ADC Resolution
The ADC of the STM32F446RE offers a resolution of 6, 8, 10 or 12 bit. A higher resolution gives more precise data, but the ADC needs more time to sample and convert. The example uses 12 bit. The remaining settings, which are the data alignment, scan mode, continuous mode, regular conversion, rank and sampling time, are the same as on the STM32F103.
DMA Continuous Requests
This option is used together with DMA. When it is enabled, the DMA keeps requesting data from the ADC and does not have to be restarted after each transfer. It has no effect in polling mode, and it appears again in the interrupt and DMA tutorial.
End of Conversion Selection
The end-of-conversion (EOC) flag shows that a conversion has finished and that the data is ready. The setting decides whether the flag is set after each single conversion or only after a complete sequence of channels. With one channel both options behave the same. With several channels the choice matters, because an interrupt-driven design with the flag set after every channel triggers 10 interrupts per sequence when 10 channels are converted.
STM32H750 ADC Polling Setup
H750 Clock Configuration
The external 25 MHz crystal clocks the system, and the PLL raises the system clock to the maximum of 480 MHz. The ADC has its own kernel clock, which is taken from PLL2P here and can be configured separately. In this configuration the ADC kernel clock runs at 15 MHz.
H750 ADC Channel and Prescaler
The example uses ADC1 channel 3 in single-ended mode. In single-ended mode the ADC measures the voltage between the input pin and ground, which is the normal ADC mode of the other devices as well. The alternative is differential mode, where the ADC measures the voltage difference between two inputs, and it is covered in the differential ADC mode tutorial.
The ADC prescaler divides the 15 MHz kernel clock, and a prescaler of 10 gives a nominal ADC clock of 1.5 MHz. Revision V devices divide the ADC clock once more, so the real clock on those chips is 0.75 MHz, as explained in the revision V section of the conversion time tutorial.
H750 ADC Resolution
The ADC1 of the STM32H750 supports resolutions of 8, 10, 12, 14 and 16 bit, and a higher resolution again needs more conversion time. The example uses 16 bit, so the largest raw value is 65535. The scan mode, continuous mode, end of conversion, regular conversion, rank and sampling time settings are the same as on the STM32F446.
Left Bit Shift
The left bit shift moves the converted value to the left by a selected number of bits. It is not needed in this tutorial and stays disabled.
Converted Data Management Mode
This setting decides what happens to the converted data. The data can be transferred by DMA, passed to the DFSDM (Digital Filter for Sigma-Delta Modulators), or left in the ADC data register. Polling reads the data register directly, so the data stays in the register.
ADC Oversampling
Hardware oversampling is not used here, so all oversampling settings stay at their defaults. The technique has its own post, the ADC oversampling tutorial.
STM32 ADC Potentiometer Wiring
The potentiometer is connected to the STM32H750 board as listed in the table below. I am using a10k slider potentiometer module for the test, and the board is the STM32H750 development board.
| Potentiometer pin | Connected to |
|---|---|
| VCC | 3.3V on the STM32 |
| GND | GND on the STM32 |
| OUT | PA6 (ADC1_INP3) |
On the STM32F103 and STM32F446 the OUT pin goes to PA0, which is the ADC1_IN0 pin configured earlier. The voltage on the ADC pin must always stay between 0 V and the ADC supply voltage, so the potentiometer is powered from 3.3V.
STM32 ADC Polling Mode HAL Code
The same HAL functions are used on all STM32 series. The calibration call before the loop is the only part that differs between the devices.
Variables and Map Function
The variables and the helper function are defined first.
/* ADC full-scale value: 65535 for 16-bit (H750), 4095 for 12-bit (F103, F446) */
#define ADC_MAX_VALUE 65535
volatile uint16_t ADC_VAL = 0; /* raw ADC result */
volatile int value = 0; /* result mapped to 0-100 */
/* Maps a number from one range to another */
long map(long x, long in_min, long in_max, long out_min, long out_max)
{
return (x - in_min) * (out_max - out_min + 1) / (in_max - in_min + 1) + out_min;
}ADC_VAL is declared as a 16-bit variable, and it stores the converted value. The variable is large enough for every resolution, including 10-bit, 12-bit and 14-bit results. The volatile keyword keeps the compiler from removing the variable, so it stays visible in the debugger. The map function converts the raw result to the range 0 to 100, and the mapped value is stored in the integer variable named value.
ADC Calibration Before the First Conversion
This step is an addition to the basic example. The STM32F1 and STM32H7 ADCs have a calibration function, and running it once after power-up improves the accuracy of the readings. The STM32F4 ADC has no calibration function, so the STM32F446 skips this step.
/* STM32F103 */
if (HAL_ADCEx_Calibration_Start(&hadc1) != HAL_OK)
{
Error_Handler();
}
/* STM32H750 */
if (HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK)
{
Error_Handler();
}Main Loop
The conversion runs inside the while loop, so the value is updated continuously.
while (1)
{
/* 1. Start the conversion */
if (HAL_ADC_Start(&hadc1) != HAL_OK)
{
Error_Handler();
}
/* 2. Wait up to 100 ms for the conversion to finish */
if (HAL_ADC_PollForConversion(&hadc1, 100) == HAL_OK)
{
/* 3. Read the result and map it to 0-100 */
ADC_VAL = HAL_ADC_GetValue(&hadc1);
value = map(ADC_VAL, 0, ADC_MAX_VALUE, 0, 100);
}
/* 4. Stop the ADC */
HAL_ADC_Stop(&hadc1);
HAL_Delay(500); /* read the input twice per second */
}How the Polling Code Works
The loop performs the four steps of the polling sequence.
- HAL_ADC_Start() starts the conversion.
- HAL_ADC_PollForConversion() waits for the end of the conversion, and the timeout of 100 ms makes the function return HAL_TIMEOUT when the ADC does not finish in time.
- HAL_ADC_GetValue() reads the converted value, which is stored in ADC_VAL.
- HAL_ADC_Stop() stops the ADC.
The largest raw value depends on the resolution and equals 2^N − 1, where N is the number of bits.
| Resolution | Largest raw value |
|---|---|
| 16 bit | 65535 |
| 14 bit | 16383 |
| 12 bit | 4095 |
| 10 bit | 1023 |
The value of ADC_MAX_VALUE in the code must match the resolution, otherwise the mapped value does not reach 100. The loop repeats every 500 ms, so the data is refreshed continuously.
STM32 ADC Polling Mode Output
The values are checked in the STM32CubeIDE debugger. Start a debug session, add ADC_VAL and value to the Live Expressions window and move the potentiometer slider. When the slider moves to the right, ADC_VAL rises towards 65535 and value rises towards 100, and moving the slider to the left lowers both values towards 0.
STM32 ADC Polling Mode Troubleshooting
| Symptom | Likely cause | What to check |
|---|---|---|
| ADC_VAL is always 0. | The potentiometer is not connected, or the pin does not match the selected channel. | Check the wiring and confirm in CubeMX that the pin is set to the ADC input of the selected channel. |
| ADC_VAL stays at the maximum value. | The input is tied to the supply voltage, or the pin is floating. | Check that OUT is connected to the pin and GND is connected to the board. |
| HAL_ADC_PollForConversion() returns HAL_TIMEOUT. | The ADC was not started, or the conversion takes longer than the timeout. | Check the return value of HAL_ADC_Start() and the ADC clock, and increase the timeout if the sampling time is very long. |
| The mapped value never reaches 100. | ADC_MAX_VALUE does not match the resolution. | Use 4095 for 12-bit and 65535 for 16-bit. |
| The readings are noisy. | The source impedance is high, or the sampling time is short. | Use a longer sampling time, add a small capacitor at the pin, or average several readings. |
| The readings are slightly inaccurate on the F103 or H750. | The calibration was not run. | Run the calibration once before the first conversion. |
| The debugger shows no change in the variables. | The compiler optimized the variables away. | Declare the variables as volatile and use the Live Expressions window. |
Conclusion
This tutorial configured the STM32 ADC in single channel polling mode with CubeMX and HAL for the STM32F103, STM32F446 and STM32H750. The setup covered the clock, the channel, the resolution, the data alignment and the sampling time, and the HAL code started the ADC, waited for the conversion and read the result from a potentiometer that was checked in the STM32CubeIDE debugger.
Polling is the simplest way to start with the ADC, because no interrupt or DMA is involved and the code is easy to read and debug. It suits basic projects with a periodic reading and a CPU that has no time-critical work in parallel. The trade-off is that the CPU is blocked during the conversion, and the next tutorial removes that limit with interrupt and DMA mode.
Download Project Here
Download the CubeMX project files and HAL source code — all tested on real hardware.
If you find this useful, you can support us with a Donation as well.
Browse More STM32 ADC Tutorials

Arun is an embedded systems engineer with 10+ years of experience in STM32, ESP32, and AVR microcontrollers. He created ControllersTech to share practical tutorials on embedded software, HAL drivers, RTOS, and hardware design — grounded in real industrial automation experience.
Recommended Tools
Essential dev tools
Categories
Browse by platform











