AN2821 - Clock_calendar implementation on the STM32F10xxx microcontroller RTC.PDF
(
433 KB
)
Pobierz
Clock/calendar implementation on the STM32F10xxx microcontroller RTC
AN2821
Application note
Clock/calendar implementation
on the STM32F10xxx microcontroller RTC
The internal RTC (real-time clock) of the 32-bit, ARM
®
Cortex™-M3-based medium-density
STM32F10xxx microcontroller is an independent timer. It provides a set of continuously
running counters, which, using suitable software, can be used to implement a clock/calendar
function. The RTC and backup registers are supplied through a switch that draws power
from either the V
DD
supply (when present) or the backup battery. Thus the RTC runs even
when the main supply is switched off.
This application note gives an example of how to implement the clock/calendar functionality
using the medium-density STM32F10xxx microcontroller in low-power and standard
applications. The firmware example also performs leap year counting and tamper time
stamping. It provides a low-power mode demonstration and a basic RTC calibration routine
to compensate for crystal and temperature variations.
The STM3210B-EVAL board supports the firmware example described in this application
note without any modification to its hardware.
Figure 1. STM3210B-EVAL board
April 2009
Doc ID 14949 Rev 2
1/28
www.st.com
Contents
AN2821
Contents
1
Overview of the medium-density STM32F10xxx backup domain . . . . . 6
1.1
Main backup domain features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.2
Main RTC features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2
Configuring the RTC registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3
Clock/calendar functionality features . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.1
Clock/calendar basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.1.1
Implementing the clock function on the medium-density STM32F10xxx . 9
3.1.2
Implementing calendar function on the medium-density STM32F10xxx . 9
3.1.3
Summer time correction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.2
Clock source selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.3
Calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.4
Low-power modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.4.1
Stop mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.4.2
Standby mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.5
Tamper detection and time stamping . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.5.1
TAMPER-RTC pin functionality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.5.2
Tamper timestamping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.5.3
Battery tamper timestamping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4
Firmware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5
Hardware description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
6
Running the demonstrator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6.1
Clock/calendar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6.1.1
Setting the time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6.1.2
Setting the alarm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6.1.3
Setting the date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6.1.4
Summer time correction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6.2
Low-power demonstration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6.2.1
Stop mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
6.2.2
Standby mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2/28
Doc ID 14949 Rev 2
AN2821
Contents
6.3
Timestamping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
6.3.1
Tamper events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
6.3.2
Battery removal and installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
6.4
Clock calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6.5
Clock source selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
6.5.1
50 Hz time base selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
6.5.2
60 Hz time base selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Appendix A Calibration table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Appendix B Additional notes on calibration and clock accuracy . . . . . . . . . . . 25
7
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Doc ID 14949 Rev 2
3/28
List of tables
AN2821
List of tables
Table 1.
Calibration lookup table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Table 2.
Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4/28
Doc ID 14949 Rev 2
AN2821
List of figures
List of figures
Figure 1. STM3210B-EVAL board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Figure 2. RTC block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Figure 3. Time system flowchart
(1)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Figure 4. Calendar algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 5. Leap year flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 6. Calibration process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Figure 7. Stop mode entry sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Figure 8. Standby mode entry sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Figure 9. STM3210B-EVAL board description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Figure 10. RTC time base connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Figure 11. Clock source selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Doc ID 14949 Rev 2
5/28
Plik z chomika:
kaczor1000
Inne pliki z tego folderu:
USART protocol used in the STM32™ bootloader.PDF
(508 KB)
TN0132 - STM32 Serial Wire Viewer (SWV) and Embedded Trace Macrocell (ETM)capabilities. Examples and technical note..PDF
(650 KB)
tn0132.zip
(608 KB)
STM32F100xx, STM32F101xx, STM32F102xx and STM32F103xx system memory boot mode.PDF
(199 KB)
Implementing an RC5 infrared remote control receiver with the STM32F10xx microcontrollers.PDF
(473 KB)
Inne foldery tego chomika:
[KURS] EdW - Mikrokontrolery z rdzeniem ARM
Dokumenty
Firmware
LIB
Noty Katalogowe
Zgłoś jeśli
naruszono regulamin