Real-time Clock (RTC)
User Manual All information provided in this document is subject to legal disclaimers. © REALTEK 2019. All rights reserved.
241
11.4
Operation Flow
11.4.1
Initialize the Calendar
The initialization calendar configure flow is shown in Table 11-3.
Table 11-3 Initialization calendar configure flow
Step What to do
How to do
Comments
1
Disable the RTC registers write protection
Write ‘0xCA’ and then ‘0x53’
into the RTC_WPR register
RTC registers can be modified
2
Enter Initialization mode
Set INIT bit to ‘1’ in RTC_ISR
register
The calendar counter is stopped to allow update
3
Wait for the confirmation of Initialization
mode (clock synchronization)
Poll INITF bit of in RTC_ISR
until it is set
It takes approximately 2 RTCCLK clock cycles for
medium density devices
4
Program the prescaler register if needed
Configure RTC_PRER register
By default, the RTC_PRER prescalers register is
initialized to provide 1Hz to the Calendar unit when
RTCCLK = 32.768kHz
5
Load time value in the shadow registers
Set RTC_TR
-
6
Configure the time format (12h or 24h)
Set FMT bit in RTC_CR register
FMT = 0: 24 hour/day format
FMT = 1: AM/PM hour format
7
Exit Initialization mode
Clear the INIT bit in RTC_ISR
register
The current calendar counter is automatically
loaded and the counting restarts after 4 RTCCLK
cycles
8
Enable the RTC registers Write protection
Write ‘0xFF’ into the RTC_WPR
register
RTC registers can no longer be modified
11.4.2
Configure Alarm
The alarm configure flow is shown in Table 11-4.
Table 11-4 Alarm configure flow
Step What to do
How to do
Comments
1
Disable the RTC registers write
protection
Write ‘0xCA’ and then ‘0x53’ into the
RTC_WPR register
RTC registers can be modified
2
Disable alarm
Clear the ALME bit in RTC_CR register
-
3
Check that the RTC_ALRMA register
can be accessed
Poll the ALMWF bit until it is set in
RTC_ISR register.
It takes approximately two RTCCLK clock cycles
(clock synchronization).
4
Configure the alarm
Configure RTC_ALMR1L and
RTC_ALMR1H register
The alarm hour format must be the same as the
RTC Calendar
5
Re-enable alarm
Set the ALME bit in RTC_CR register
-
6
Enable the RTC registers write
protection
Write "0xFF" into RTC_WPR register
RTC registers can no longer be modified
Note
:
The alarm behaviour can be configured using the MSK
x
bits (
x
= {0, 1, 2, 3}) of the RTC_ALMR1L and RTC_ALMR1H registers.
Alarm can also be configured in the initialization mode.
11.4.3
Configure Calibration
The calibration configure flow is shown in Table 11-5.
Table 11-5 Calibration configure flow
Step What to do
How to do
Comments
The document authorized to
2019-05-15 10:08:03