版本 3a557f1cfe2c6c42cc3b54123f758c6afc705d1a
embedded/RTC
Introduction
A real-time clock (RTC) is a computer clock that keeps track of the current time. RTCs are also present in almost any electronic device that requires accurate time keeping. The real-time clock (RTC) embedded in STM32 microcontrollers acts as an independent BCD timer/ counter.
Features
Calendar
Alarm
Auto wakeup
Timestamp
Tamper detection
Programmable daylight saving time
Didigal calibration
Synchronization by shifting
Reference clock detection
Backup register
Alternative function IO
Clock Source
LSI RC : 32 kHz
LSE OSC : 32.768 kHz
HSE OSC : 4-26 MHz
.. image:: /stm32F4 RTC clock source
Prescaler
Prescaler generates the clock to update update the calendar.
To minimize power comsuption the prescaler is split into two prescalers, asynchronous and synchronous. It is recommended to configure the asynchronous prescaler to a high value to minimize consumption.
asynchronous prescaler clocks subsecond of calendar and propagates to synchronous prescaler to update date and time by second.
One can configure them through PREDIV_A
and PREDIV_S
bits in RTC_PRER
Calendar
A calendar keeps track of the date (day, week, month, year) and time (hours, minutes and seconds) and even subseconds. It manages of numbers of days of mouths automaticly. Daylight saving time adjustment is programmable by software.
Binary repersentation is in binary-coded decimal (BCD) format.
Data can be read indirectly from shadow registers or directly from connters. The former method delays some clocks but ensures consistency between date and time registers; the later is opposite but this is especially useful after exiting from low power modes, since the shadow registers are not updated during these modes.
Data, time, and subsecond corresponds to RTC_DR
, RTC_TR
, and RTC_SSR
. With BYPSHAD
bit set, data can be read directly from counter.
Synchronization and Reference clock detection
RTC can be synchronized to remote clock by adding a ‘shift’ to counter continuously to delay, or vice versa. With reference clock detection, RTC shifts misaligned 1 Hz clock to align it with the nearst referenced edge (found in a given time window).
One can adjust time by configuring shift through RTC_SHIFTR
.
When reference clock detection is enabled (REFCKON
), must not write RTC_SHIFTR
and not enable calibration and set prescalers (PREDIV_A
and PREDIV_S
) to default.