This project demonstrates the ADC Scan Mode feature in STM32 microcontrollers, which automates the sequential sampling of multiple analog channels. Like a conductor guiding an orchestra, Scan Mode ensures smooth and efficient channel switching without manual reconfiguration between conversions.
By combining Scan Mode with DMA, the system automatically transfers conversion results to memory, minimizing CPU intervention and enabling multitasking. Results are transmitted via UART for real-time monitoring. The setup is simulated in Proteus 8.
STM32CubeMX Setup- MCU: STM32F103C6 (8 MHz system clock)
- GPIO Configuration
-
PA1 → Output (LED – Scan Completion Indicator)
-
PA2 → Output (LED – Loop Activity Indicator)
- ADC1 Configuration
-
Enable Scan Conversion Mode
-
Number of Conversions: 2 (Channel 8 (PB0) → Rank 1 ,Channel 9 (PB1) → Rank 2)
-
Trigger Source: Software Start
-
DMA: Enable (Circular Mode, 16-bit width)
- UART1 Configuration
-
Baud Rate: 115200
-
Asynchronous mode
-
8-bit data, 1 stop bit, no parity
- Generate project and open in STM32CubeIDE
- DMA Initialization
-
Start DMA transfer with HAL_ADC_Start_DMA()
- Conversion Complete Callback
-
HAL_ADC_ConvCpltCallback()
-
Toggle PA1 LED when scan conversion is complete
- Main Loop
-
Transmit ADC values over UART using HAL_UART_Transmit()
-
Toggle PA2 LED periodically to show system activity
Required Components
- STM32F103C6 MCU
- 2× Potentiometers (connected to PB0 / PB1 → ADC Channels 8 & 9)
- 2× LEDs (connected to PA1 / PA2)
- Virtual Terminal (connected to PA9 / UART1 TX)
Steps
- Connect potentiometers to ADC1 Channels 8 & 9 (PB0, PB1)
- Connect PA1 and PA2 to LEDs
- Connect PA9 (TX) → Virtual Terminal
- Load compiled .hex file into STM32
- Run simulation:
-
Rotate potentiometers to vary ADC values
-
Observe sequential ADC values on the Virtual Terminal
-
LEDs indicate scan completion and system activity
If you have any questions or suggestions don't hesitate to leave a comment below
Comments