This project demonstrates how to interface an STM32 microcontroller with an ST7735 color TFT display using SPI communication. The ST7735 is a compact display controller capable of rendering graphics and text at 128x160 resolution with support for up to 262,144 colors. The project covers low-level initialization, pixel drawing, and higher-level functions for rendering shapes and text, providing a foundation for embedded graphics applications.
STM32CubeMX Configuration- Create a new STM32F103C6 project.
- Set RCC → High Speed Clock (HSE) to Crystal/Ceramic Resonator.
- In Clock Configuration, set the system clock to 72 MHz.
- Configure SPI1 in Transmit Only Master mode.
- GPIO Configuration:
- PB13 as SPI1_SCK (alternate function push-pull)
- PB15 as SPI1_MOSI (alternate function push-pull)
- PB0 as GPIO Output (Chip Select - CS)
- PB12 as GPIO Output (Reset - RST)
- PB14 as GPIO Output (Data/Command - DC)
- Set SPI1 prescaler to 16 (achieving ~4.5 MHz SPI clock at 72 MHz system clock).
- Generate initialization code.
- Open the generated project.
- Create Display Driver Files:
- ST7735_cfg.h: Pin mapping and display-specific settings.
- ST7735.h / ST7735.c: Low-level commands, initialization sequence, and core functions (pixel draw, fill screen).
- fonts.h / fonts.c: Font definition structures and character data.
- testimg.h: Array storing image data for display tests.
- Implement Core ST7735 Functions:
- ST7735_Init(): Sends initialization commands to configure the display.
- ST7735_DrawPixel(): Sets a single pixel to a specified color.
- ST7735_FillScreen(): Fills the entire screen with a color.
- ST7735_DrawString(): Renders a text string using a specified font and colors.
- Application Logic (main.c):
- Initialize SPI and GPIO.
- Call ST7735_Init().
- Use drawing functions to display graphics, text, and images.
- Build the project.
- Add STM32F103C6 and ST7735 TFT display components.
- Wiring:
- Connect STM32 SPI pins (PB13-SCK, PB15-MOSI) to ST7735 (SCL, SDA).
- Connect STM32 control pins (PB0-CS, PB12-RST, PB14-DC) to ST7735.
- Connect VCC (3.3V) and GND.
- Load the compiled .hex file into the MCU.
- Start simulation and observe graphics output on the ST7735 display.
If you have any questions or suggestions don't hesitate to leave a comment below
Comments