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:
-
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.
-
Fourth, the second interrupt
(3) Write void RTC_init(u8 HH, u8 MM, u8 SS) initial function
(4) Write void RTC_IRQHandler(void) second interrupt function
(5) Write void DealWith_0(void) clock data processing function
(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