This project demonstrates how to interface the ADC128S102 12-bit analog-to-digital converter (ADC) with an STM32F103C6 microcontroller via SPI communication.
The ADC128S102 provides eight input channels with 12-bit resolution and supports conversion rates from 50 kSPS to 1 MSPS, making it suitable for high-speed data acquisition systems. By integrating with STM32, the system achieves multi-channel analog data acquisition, processed in real-time and transmitted through UART monitoring for debugging or display.
STM32CubeMX Setup- MCU Selection: STM32F103C6 (8 MHz clock)
- SPI1 Configuration:
-
Mode: Full-Duplex Master
-
Data Size: 8-bit
-
Prescaler: 32 (250 kHz clock)
-
CPOL: Low, CPHA: 1 Edge
- GPIO Configuration:
-
PA4 → Output (Chip Select)
- UART1 Configuration:
-
Mode: Asynchronous
-
Baud Rate: 115200
-
Word Length: 8 bits
- Generate initialization code in STM32CubeIDE.
Key Functions
- SPI Initialization
-
Configures SPI communication and prepares ADC for channel reads.
-
void ADC128S102_Init(void);
- Channel Reading
-Selects input channel (CH0–CH7), initiates conversion, and returns 12-bit result.
-
uint16_t Read_ADC_Channel(uint8_t channel);
- Main Loop
-
Continuously acquires ADC values and prints results in volts via UART.
-
uint16_t val = Read_ADC_Channel(ch);
-
printf("CH%d: %.2fV\r\n", ch, (val * 3.3f / 4095));
Components
- STM32F103C6 microcontroller
- ADC128S102 ADC
- 8× Potentiometers (POT-HG) for input channels
- Virtual Terminal (UART display)
Steps
- Connect SPI pins:
-
PA5 → SCLK
-
PA6 → MISO
-
PA7 → MOSI
-
PA4 → CS (chip select)
- Connect potentiometers to ADC CH0–CH7 inputs.
- Link UART1 (PA9 → TX) to Virtual Terminal.
- Load the generated .hex file into STM32 in Proteus.
- Adjust potentiometers to vary input voltages.
- Monitor ADC readings in volts on the Virtual Terminal.
If you have any questions or suggestions don't hesitate to leave a comment below
Comments