(6) Lanqiao Cup Embedded-Real Time Clock

(1) Personal habits

Will create separate RTC.c and RTC.h and put them under the HARAWARE folder

(2) Preparation

  • 1. Introduction to RTC
    STM32's real-time clock (RTC) is aIndependent timer.
    The RTC module of STM32 has a set of counters that count continuously.
    Under the corresponding software configuration, it can provideClock calendarFunction.
    Modifying the counter value can reset the current time and date of the system.
    The RTC module and clock configuration system (RCC_BDCR register) are inReserve area.
    The RTC settings and time remain unchanged after system reset or wake-up from standby mode.
    After the system is reset, it willAutomatically banAccess back-up registers and RTC to prevent accidental write operations to the back-up area (BKP).
    Before setting the time, firstCancel the write protection of the backup area (BKP)

  • Second, see here that power control (PWR) and **backup register (BKP)** are very important-related documents:Insert picture description here
    Insert picture description here

  • 3. Clock source selection
    So a very important point is here. Our Lanqiao Cup embedded board can only use LSI clock source. According to official instructions, other clock sources are not available, so this point is very important.
    Insert picture description here

  • Fourth, the second interrupt
    Insert picture description here

(3) Write void RTC_init(u8 HH, u8 MM, u8 SS) initial function

Insert picture description here

(4) Write void RTC_IRQHandler(void) second interrupt function

Insert picture description here

(5) Write void DealWith_0(void) clock data processing function

Insert picture description here

(6) Problem

The read clock data TimeVal 1 represents 1 second, and 1 hour = 3600 seconds. So:
Hours = TimeVal / 3600 seconds
Minutes = TimeVal% 3600/60 seconds
Seconds = TimeVal% 3600% 60 seconds

Guess you like

Origin blog.csdn.net/m0_46278925/article/details/113436777