This project demonstrates how to create a dynamic digital clock using an STM32F407 microcontroller and an LCD1602 display with I2C communication via a PCF8574 I/O expander.
- Real-time display of current date and time
- I2C communication via PCF8574
- Configurable alarm and wake-up interrupts
- LCD backlight control based on alarm state
- Microcontroller: STM32F407
- Display: LCD1602 with I2C interface (PCF8574)
- I2C Pins:
- SDA → PB7
- SCL → PB6
- Uses the I2C1 peripheral for communication with the LCD.
- Time and date are configured once during initialization.
- Note: After regenerating code with STM32CubeMX, ensure that the initialization code in
rtc.c
underUser Code 2
is moved above the configuration of the wake-up and alarm interrupts. - Alarm settings include configurable mask bits to control which time components (e.g., hours or dates) should trigger the alarm.
- Wake-Up Interrupt:
- Sets an external flag
updateLCD
- The
while
loop inmain()
checks this flag to update the display with the current time
- Sets an external flag
- Alarm Interrupt:
- Turns off the LCD display
- Disables wake-up interrupts
- Resets the
updateLCD
flag
- Configure peripherals in STM32CubeMX, ensuring RTC and I2C are properly set.
- Generate code and adjust the position of RTC initialization code as noted above.
- Flash the firmware to your STM32F407 board.
- The LCD will show the current date and time, updated dynamically via I2C.
- STMicroelectronics for STM32 and CubeMX tools
- Open-source LCD1602 + PCF8574 libraries for STM32