This project demonstrates how to implement a Real-Time Clock (RTC) using an STM32F103C6 microcontroller. The system displays the current time and date on an ST7735 TFT display and allows configuration via UART commands.
By leveraging the STM32 internal RTC with a 32.768 kHz crystal, this solution ensures accurate timekeeping. The SPI-driven TFT display provides a clear visual interface, while UART enables easy user configuration of time and date. A full Proteus simulation setup is included for validation.
STM32CubeMX Setup- MCU Selection: STM32F103C6 (72 MHz clock)
- RTC Configuration:
-
Clock Source: LSE (32.768 kHz crystal)
-
Asynchronous Prescaler: 127
-
Synchronous Prescaler: 255
- SPI1 Configuration:
-
Mode: Transmit Only Master
-
Prescaler: 4 (18 MHz baud rate)
- UART1 Configuration:
-
Baud Rate: 115200
-
Word Length: 8 bits
-
Parity: None
-
Stop Bits: 1
- Generate initialization code in STM32CubeIDE.
Key Functions
- RTC Time & Date Configuration
- void Set_RTC_TimeAndDate(void);
- Configures time and date via UART input.
Display Operations
- ST7735_WriteString(5, 5, "14:30:00", Font_7x10, WHITE, BLACK); // Time display
- ST7735_WriteString(5, 20, "12/05/24", Font_7x10, WHITE, BLACK); // Date display
- Main Loop
while (1)
{
// Update display with current RTC time
Update_Display_With_RTC();
// Send time data via UART
Send_RTC_Time_UART();
HAL_Delay(1000);
}
Required Components:
- STM32F103C6 microcontroller
- ST7735R TFT display
- Virtual Terminal (UART)
- 32.768 kHz crystal
Connections:
- SPI1: PA5 → SCK, PA7 → MOSI, PA4 → CS, PA3 → DC
- UART1: PA9 (TX) → USB-UART RX
- RTC Crystal: 32.768 kHz connected to PC14/PC15
- Power: 3.3V
Steps:
- Load the.hex file from CubeIDE.
- Configure time via UART terminal (format: HH:MM:SS).
- Observe real-time updates on the ST7735 display.
- Monitor time output on the Virtual Terminal.
If you have any questions or suggestions don't hesitate to leave a comment below
Comments