You Are Here: Home » AVR ATmega Projects » Clock Projects » DS1307 RTC Interfacing with AVR microcontroller

DS1307 RTC Interfacing with AVR microcontroller

In this tutorial we will learn How to interface RTC DS1307 with AVR microcontroller.
We are using Atmega8 for the demo.Schematic DS1307 RTC Interfacing with AVR microcontroller

The DS1307 serial real-time clock (RTC) is a low-power, full binary-coded decimal (BCD)
clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially through
an I2C™, bidirectional bus. The clock/calendar provides seconds, minutes, hours, day, date,
month, and year information. The end of the month date is automatically adjusted for months
with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-
hour or 12-hour format with AM/PM indicator. The DS1307 has a built-in power-sense circuit
that detects power failures and automatically switches to the battery supply.


  • Real-Time Clock (RTC) Counts Seconds, Minutes, Hours, Date of the Month, Month,
  • Day of the week, and Year with Leap-Year Compensation Valid Up to 2100
  • 56-Byte, Battery-Backed, Nonvolatile (NV) RAM for Data Storage
  • I2C Serial Interface
  • Programmable Square-Wave Output Signal
  • Automatic Power-Fail Detect and Switch Circuitry
  • Consumes Less than 500nA in Battery-Backup Mode with Oscillator Running
  • Optional Industrial Temperature Range: -40°C to +85°C
  • Available in 8-Pin DIP or SO
Pin Diagram of RTC DS1307:Diagram DS1307 RTC Interfacing with AVR microcontrollerPIN DESCRIPTION:

X1 and X2 (pin 1,2): Connections for Standard 32.768kHz Quartz Crystal. The internal oscillator circuitry is designed for operation with a crystal having a specified load capacitance (CL) of 12.5pF. X1 is the input to the oscillator and can optionally be connected to an external 32.768kHz oscillator. The output of the internal oscillator, X2, is floated if an external oscillator is connected to X1.

VBAT (pin 3): Backup Supply Input for Any Standard 3V Lithium Cell or Other Energy Source. Battery voltage must be held between the minimum and maximum limits for proper operation. Diodes in series between the battery and the VBAT pin may prevent proper operation. If a backup supply is not required, VBAT may be grounded. The nominal power-fail trip point (VPF) voltage at which access to the RTC and user RAM is denied is set by the internal circuitry as 1.25 x VBAT nominal. A lithium battery with 48mAhr or greater will back up the DS1307 for more than 10 years in the absence of power at +25°C.
GND (pin 4): Ground
SDA (pin 5): Serial Data Input/Output. SDA is the data input/output for the I2C serial interface. The SDA pin is open drain and requires an external pullup resistor.
SCL (pin 6): Serial Clock Input. SCL is the clock input for the I2C interface and is used to synchronize data movement on the serial interface.
SWQ/OUT (pin 7): Square Wave/Output Driver. When enabled, the SQWE bit set to 1, the SQW/OUT pin outputs one of four square-wave frequencies (1Hz, 4kHz, 8kHz, 32kHz). The SQW/OUT pin is open drain and requires an external pullup resistor. SQW/OUT operates with either VCC or VBAT applied.
VCC (pin 8): Primary Power Supply. When voltage is applied within normal limits, the device is fully accessible and data can be written and read. When a backup supply is connected to the device and VCC is below VTP, read and writes are inhibited. However, the timekeeping function continues unaffected by the lower input voltage.

Leave a Comment

You must be logged in to post a comment.

Read previous post:
Tools for the Electronics Hobbyist Part 1- Graphical Components Tester

When I started to deal with Chinese electronics suppliers from websites like Alibaba, Aliexpress and Taobao, I discovered that there...

Scroll to top