Problem interfacing the DS1307 with the Arduino Duemilanove

Hi,

A part of our project requires setting and reading the time from an RTC.

We've used the DS1307 IC and made the circuit connections as shown in the attachment.

We used the code provided on this link to test our RTC:

Which is this basically:

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

void setup () {
Serial.begin(57600);
Wire.begin();
RTC.begin();

if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
//RTC.adjust(DateTime(DATE, TIME));
}

}

void loop () {
DateTime now = RTC.now();

Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();

Serial.print(" since 1970 = ");
Serial.print(now.unixtime());
Serial.print("s = ");
Serial.print(now.unixtime() / 86400L);
Serial.println("d");

// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now.unixtime() + 7 * 86400L + 30);

Serial.print(" now + 7d + 30s: ");
Serial.print(future.year(), DEC);
Serial.print('/');
Serial.print(future.month(), DEC);
Serial.print('/');
Serial.print(future.day(), DEC);
Serial.print(' ');
Serial.print(future.hour(), DEC);
Serial.print(':');
Serial.print(future.minute(), DEC);
Serial.print(':');
Serial.print(future.second(), DEC);
Serial.println();

Serial.println();
delay(3000);
}

We un-commented the RTC.adjust() function to set the RTC to the PC time. Running the code gives us the output shown in the attachment.

We've connected the SDA pin (pin 5) of DS1307 to the Analog pin 4 of the Duemilanove and its SCL pin (pin 6) to Analog pin 5 of the Duemilanove.

Please help rectify any mistake.

Thanks.

Take a look at the DS1307 data sheethttp://datasheets.maximintegrated.com/en/ds/DS1307.pdf

The maximum VBAT is specified as 3.5v and you have it connect to the 5v. The nominal is 3v.

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 must 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.

Try grounding the VBAT., and running the sketch at least once with the comment lines removed from

//RTC.adjust(DateTime(__DATE__, __TIME__));

That will set the ClockHalt bit. If this fixes the problem and the RTC runs, you will have to come up with a battery or a lower voltage source to VBAT as the RTC will not update the time when the power is off.