This project demonstrates how to interface a 128×64 SSD1306 OLED display with an STM32F103C6 microcontroller using the SPI protocol. The SSD1306 is a popular choice for compact and low-power displays, providing flexibility to render text, graphics, and animations.
Compared to character LCDs, OLED displays are:
- Compact – perfect for portable and wearable applications (e.g., smartwatches)
- Aesthetic – clear text and smooth graphics
- Cost-effective – more affordable than graphic LCDs while offering better features
This project covers hardware setup, SPI configuration, and basic graphics rendering. Simulation is performed in Proteus 8.
STM32CubeMX Setup- MCU Selection: STM32F103C6 (8 MHz system clock)
- SPI1 Configuration
-
Mode: Transmit Only Master
-
Prescaler: 8 (SPI baud rate ≈ 4 Mbps)
-
Data Size: 8 bits
- GPIO Configuration
-
PA3 → DC (Data/Command select) → Output Push-Pull
-
PA4 → CS (Chip Select) → Output Push-Pull
-
PA5 → SCK (SPI Clock) → Alternate Function Push-Pull
-
PA7 → MOSI (SPI Data) → Alternate Function Push-Pull
- Generate project and open in STM32CubeIDE
Key Files
- oled.c / oled.h
-
SSD1306_Init() → Initialize display
-
SSD1306_WriteString() → Display text
-
SSD1306_DrawLine() → Render simple graphics
- fonts.c / fonts.h
-
Store font data (e.g., 8×6, 12×6 pixel fonts)
- main.c
-
Call SSD1306_Init() after HAL initialization
-
Example:
SSD1306_Clear();
SSD1306_WriteString("Hello, OLED!", Font_11x18, White);
SSD1306_UpdateScreen();
Required Components
- STM32F103C6
- SSD1306 OLED (SPI)
- Power (VCC, GND)
Connections
- PA5 → SCK
- PA7 → MOSI
- PA4 → CS
- PA3 → DC
- VCC, GND → Power supply
Steps
- Load the compiled .hex file into STM32
- Run simulation in Proteus
- Observe “Hello, OLED!” message and graphics on the SSD1306 display
If you have any questions or suggestions don't hesitate to leave a comment below
Comments