1 starting and stopping the rtc, 2 setting and reading the rtc time registers, Real-time clock – Maxim Integrated High-Speed Microcontroller User Manual
Page 157
High-Speed Microcontroller User’s Guide
Rev: 062210
157 of 176
14.1 Starting and Stopping the RTC
Setting the RTC enable bit, RTCE (
.0), to 1 enables RTC operation. This starts the RTC crystal
amplifier and begins clocking the RTC. Like all crystal oscillators, the RTC crystal oscillator has a crystal
warmup period. Software should allow a minimum of 1 second between setting the RTCE bit to 1 and
initializing the time. This allows the clock to be guaranteed stable when timekeeping begins. Although it
may be desired to program the RTC time registers and then start the oscillator, this sequence is not
recommended because of the delay incurred by the RTC crystal warmup period.
There are two situations where the RTC will be started. The first is the case where the RTC has been
intentionally halted following normal operation. When the RTCE bit is set, the time registers will
continue their count from the last setting when the clock was stopped. The RTC time value will be
inaccurate, although the settings of the RTC alarm registers and the
register will remain intact.
The second case is following the application of battery power. Most of the registers associated with the
RTC are nonvolatile, so that they will maintain their state while V
CC
is removed. When battery power is
applied to the device, however, the battery backed registers and bits associated with the RTC will be in an
indeterminate state and will need to be reinitialized. This includes the RTC interrupt flag, RTCIF
(
.1), which should be cleared before setting the RTC interrupt-enable bit (
.5).
Clearing the RTCE bit to 0 halts the RTC. This will immediately halt the RTC and will freeze all the time
registers at their current value and preserve all the RTC settings. If RTC functions are not desired, this
can be used to reduce the power consumption of the device while in battery-backed mode.
14.2 Setting and Reading the RTC Time Registers
Access to the RTC time registers (
,
,
,
.2) bits. Both user software and the internal clock directly
write and read the RTC time. To prevent the possibility of both user software and the internal timer
accessing the same register simultaneously, the DS87C530 incorporates a register locking mechanism.
Updates to the RTC time registers by the internal timer are temporarily suspended for up to 1.95ms
during software read or write operations. If a subsecond timer tick should occur during the 1.95ms
window, it will be processed immediately as soon as either the RTCWE or RTCRE bit is cleared.
Because the subsecond timer tick interval is 3.906ms, the 1.95ms window allows sufficient time to
complete any operations and process suspended timer ticks before the next timer tick occurs. In this way,
no timer ticks can be lost, and accessing the time registers will not affect the accuracy of the RTC. To
allow any pending timer ticks to propagate through the RTC circuitry, software must wait 4 machine
cycles after setting the RTCWE or RTCRE bits before accessing any of the RTC time registers. The first
timer tick following the clearing of the RTCWE bit will be approximately 1.95ms. All following timer
ticks will be 3.90625ms.
Reading the current time from any or all of the RTC time registers is accomplished by the following
procedure:
1) Disable all interrupts by clearing the EA bit (
2) Set the RTCRE bit (
3) Wait 4 machine cycles.
4) Read the appropriate register(s) within 1ms of RTCRE being set.
5) Clear the RTCRE bit (
.3).
6) Enable interrupts by setting the EA bit (