AN1780
APPLICATION NOTE
STR71X REAL TIME CLOCK APPLICATION EXAMPLE
INTRODUCTION
The purpose of this application note is to explain how to use the STR71x Real Time Clock
(RTC) peripheral.
eral, in terms of prescaler and interrupts, to be used to keep the time and date and to generate
Alarm interrupts
counters are designed to continuously count time in seconds. This application note addresses
how to convert the 32-bit time value into a date and time value that can be put in the following
form MM/DD/YYYY, HH:MM:SS.
The date used in this application note is the same used with the UNIX operating system, the
reference date January 1, 1970, often referred to as Unix Epoch.
This document in organized in two sections, the first presents the STR71x RTC peripheral and
how to configure it and generate a fixed time base, the second part describes the related soft
ware required for the application.
As an application example, it demonstrates how to setup the RTC periph-
.The STR71x RTC has a 32-bit binary counter register. The 32-bit binary
-
-
This application note deals with various techniques for keeping time with the STR71x.
For more information about the STR71x RTC peripheral refer to STR71x Reference Manual.
Note: Because of the reference date used and the use of a 32-bit counter, this algorithm rolls
over on Tuesday, January 19, 03:14:07, 2038.
The following application note developed using RVDK Toolchain V1.6.1 and the STR710 Evalboard.
You must have the ARM Real View Developer Kit to get the most out of this Application Note.
AN1780/1204 1/9
1
STR71X REAL TIME CLOCK APPLICATION EXAMPLE
1 WHAT IS A REAL TIME CLOCK?
A real time clock is a clock that keeps track of the time even when the system is turned off. In
contrast, clocks that are not real-time do not function when the system is off. Most of the realtime clocks operate at 32.768KHz.
2 APPLICATIONS—TIME AND ATTENDANCE
Real Time Clocks are usually found in portable systems such as a data collection terminals
and smart card readers which are required to keep track of the day and time of certain tasks
taking place. After the tasks are completed, usually the portable system will return to a standby mode to conserve power. The alarm can be set to wake up the system at certain time inter
vals to perform other tasks or to repeat the process. For example, in an access control application, when someone tries to access the building through certain doors, the day and time of
the entry is recorded and this information can be used for accounting and security purposes,
etc.
-
3 STR71X RTC PERIPHERAL
The RTC peripheral implemented in the STR71x family is a 32-bit continuously running
counter that can be used, with a few configuration parameters, to provide a precise clock-cal
endar function.
The RTC peripheral is mapped on the APB2 bridge and clocked by an external 32.768 kHz oscillator through a 32-bit prescaler register, this prescaler can be used to vary the RTC clock
from 32.768 kHz to 0.5 Hz.
Figure 1. RTC Peripheral
32.768 kHz
20-bit Prescaler register
RTC (32-bit) programmable Counter Registers
In this application, the RTC counter registers have to be incremented every second, this can
be configured by using a prescaler value of 0x8000 (32768) to slow down the RTC clock from
32768 Hz to 1 Hz. This allows the RTC to keep time in seconds in the 32-bit counter.
-
2/9
2
STR71X REAL TIME CLOCK APPLICATION EXAMPLE
4 CONFIGURATION MODE
To write in the RTC_PRL, RTC_CNT, RTC_ALR registers, the peripheral must enter Configuration mode. This is done by setting the CNF bit in the RTC_CRL register.
In addition, writing to any RTC register is only enabled if the previous write operation is finished.
To enable the software to detect this situation, the RTOFF status bit is provided in the
RTC_CR register to indicate that an update of the registers is in progress. A new value can be
written to the RTC counters only when the RTOFF status bit value is ’1’.
Configuration Procedure:
1. Poll RTOFF, wait until its value goes to ‘1’
2. Set CNF bit to enter configuration mode
2. Write to one or more RTC registers
3 Clear CNF bit to exit configuration mode
The write operation only executes when the CNF bit is cleared and it takes at least two
Clock32 cycles to complete.
5 32-BIT COUNTER TIME CONVERSION
This application note explains how to convert the 32-bit time value into a date and time value
that can be put in the form of MM/DD/YYYY, HH:MM:SS. Many functions provided by the ARM
compiler used to convert from a date and time to seconds are also described.
These functions are modified in order to explore the STR71x RTC to deliver time and date.
5.1 C LIBRARY FUNCTIONS USED
5.1.1 RTC prescaler Initialisation:
Before start-up we must adjust the STR71x RTC prescaler register value in order to have the
RTC counter registers incremented every second, this can be configured by using a prescaler
value of 0x8000 (32768) to slow down the RTC clock from
5.1.2 Origin Date Adjust
Since the date used in this application note is the same used with the UNIX operating system,
the reference date January 1, 1970, often referred to as Unix Epoch, we must
0x3FF36300 to the value obtained from the STR71x RTC Counter register with intent to have
a start date = 01/01/2004.
32768 Hz to 1 Hz.
add this number
3/9