Freescale Semiconductor
Order this document
by AN1759/D
AN1759
Freescale Semiconductor, Inc...
Add a Non-Volatile Clock to the MC68HC705J1A
By Mark Glenewinkel
Field Applications Engineering
Consumer Systems Group
Austin, Texas
Introduction
Many embedded systems require the measurement of time. This can be
accomplished internally by some MCUs that have on-chip real-time
clocks. Even so, for date, month, and leap year measurement, this task
can take substantial amounts of bandwidth and code space.
The DS1307 64x8 serial real-time clock provides calendar and time
keeping functions along with system-enhancing non-volatile RAM. With
a 2-wire interface, timekeeping can be managed easily.
Some applications of using the DS1307 are:
•
•
•
Logging of chronological events
Tracking power down time of a system
Providing alarm functions
© Freescale Semiconductor, Inc., 2004. All rights reserved.
Motorola, Inc., 1998
AN1759
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc.
Application Note
The non-volatile RAM (random-access memory) also gives the user
additional applications such as:
•
•
•
Power down information storage for consumer electronics like
TVs, VCRs, and hand-held portables
Identification number storage for remote addressing or security
Storage of telecommunication information like phone number
recall and speed dialing
Freescale Semiconductor, Inc...
This application note describes the interface between the
MC68HC705J1A (J1A) and the DS1307. Circuitry and example code are
given to demonstrate the interface between the two parts.
The DS1307 provides these features:
•
•
•
•
•
•
•
•
•
Real-time clock counts seconds, minutes, hours, day of the week,
date, month, and year.
Leap year compensation valid up to 2100
56 bytes of non-volatile RAM for data storage
2-wire serial interface
Programmable square wave output with frequencies of 1 Hz,
4.096 kHz, 8.192 kHz, and 32.768 kHz
Automatic power switching to battery when main power fails
In battery backup mode, less than 500 nA consumed at 25
°C
8-pin DIP or SOIC package
Optional industrial temperature range of –40
°C
to +85
°C
Features
Description
The DS1307 is a low-power binary coded decimal (BCD) clock calendar
that provides seconds, minutes, hours, day, date, month, and year. In
addition, it has 56 bytes of non-volatile RAM. End-of-the-month
adjustments are automatic for months with less than 31 days. The
device also corrects for leap years. The clock can operate in either
12-hour or 24-hour mode. In 12-hour mode, an a.m./p.m indicator is
used.
AN1759
2
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc.
Application Note
DS1307 Hardware Interface
The DS1307 has built-in power management circuitry to detect power
failures on the V
DD
pin and when detected will switch power over to the
battery back-up pin, V
BAT
. Access to the device is terminated when V
DD
falls below 1.25 x V
BAT
. Further accesses to the device are not allowed.
On power up, the device switches power from V
BAT
to V
DD
when the V
DD
pin is 0.2 volts above V
BAT
. Once V
DD
is higher than 1.25 x V
BAT
, normal
operations can continue.
Address and data are communicated via the 2-wire bus. The DS1307
operates as a slave at all times and is accessed by first transmitting the
DS1307’s identification code on the bus.
Freescale Semiconductor, Inc...
DS1307 Hardware Interface
Pinout and Pin
Descriptions
X1
X2
V
BAT
GND
1
2
3
4
8
7
6
5
V
DD
SQW/OUT
SCL
SDA
Figure 1. DS1307 Pinout
V
DD
and GND
These pins serve as the main power source for the device. When
+5 volts is applied to this pin, the device is fully accessible and data can
be read or written. If the power on the V
DD
pin falls below 1.25 x V
DD
, the
device switches its power supply to V
BAT
. At this point, reading and
writing to the device is prohibited. The timekeeping function and non-
volatile RAM are unaffected.
This pin is the power input for any standard 3-volt lithium battery or other
3-volt source. For proper operation, this voltage must be held between
2.5 and 3.5 volts. A lithium battery with at least a 35-mA hours rating will
back up the DS1307 for more than 10 years in the absence of power.
V
BAT
AN1759
For More Information On This Product,
Go to: www.freescale.com
3
Freescale Semiconductor, Inc.
Application Note
X1 and X2
These pins are used to connect a 32.768-kHz crystal to the device. No
other capacitors or resistors are needed for this crystal circuit. The
internal oscillator circuitry is designed for a crystal with load capacitance
of 12.5 pF. For the test circuit described in this application note, an
Epson C-001R crystal was used. The Digi-key part number for this
device is SE3201-ND.
When enabled, this pin outputs one of four selectable frequencies:
•
•
•
•
1 Hz
4.096 kHz
8.192 kHz
32.768 kHz
SQW/OUT
Freescale Semiconductor, Inc...
The 1-Hz signal can be used to feed an external interrupt pin on an MCU.
This allows the MCU to use minimal bandwidth when servicing the
timekeeping function of a system.
When disabled, the pin acts as a normal output pin. It is controlled via
the DS1307 control register.
SCL
SDA
The SCL pin is the clock input for the DS1307 2-wire serial interface.
The SDA pin is an I/O pin used to transmit and receive data off the 2-wire
serial interface. SDA is an open-drain pin that requires an external pullup
resistor.
AN1759
4
For More Information On This Product,
Go to: www.freescale.com
Freescale Semiconductor, Inc.
Application Note
DS1307 Hardware Interface
Block Diagram
V
DD
V
BAT
GND
X1
POWER
CONTROL
X2
REAL-TIME
CLOCK RAM
OSCILLATOR
& DIVIDER
SQW/OUT
SQUARE
WAVE OUT
CONTROL
LOGIC
RAM
56 X 8
Freescale Semiconductor, Inc...
SDA
SCL
SERIAL
BUS INTERFACE
ADDRESS
REGISTER
Figure 2. DS1307 Block Diagram
Serial Interface
The DS1307 supports the bidirectional, 2-wire protocol. The protocol has
these characteristics:
•
•
•
•
•
•
•
•
•
•
Any device sending out data is defined as a transmitter.
Any device receiving data is defined as a receiver.
The device controlling the transfer is called the master.
The device being controlled is called the slave.
The master initiates all transactions.
The master always provides the clock for both transmit and
receive operations.
The DS1307 is always considered the slave.
The clock signal is called SCL.
The data signal is called SDA.
All data is sent most significant bit (MSB) first.
Figure 3
shows the 2-wire bus interface between a master and slave.
AN1759
For More Information On This Product,
Go to: www.freescale.com
5