Go Down

Topic: real time clock ds 1307 (Read 7 times) previous topic - next topic



im trying to use the ds 1307 realtimeclock
connected via i2c two wire bus
im able to set the the time (it seems like it works) , but if i try to read from the ds 1307 i get always the time and date i set up in 1307 memory. There is no increasement of time.
I use a 32.768 kHz quartz crystal connected to he x1/x2 pins of the RTC, if I remove it there is the same behaviour, nothing changes.

Here is the code I use:

Code: [Select]

#include <Wire.h>

byte _sec =4;
byte _min=8;
byte _hour=3;
byte _day =5;
byte _date=2;
byte _month=6;
byte _year =7;

boolean state;

void setup()
 Wire.begin();        // join i2c bus (address optional for master)
 pinMode(13, OUTPUT);
 Wire.beginTransmission(104); // transmit to device #104, the ds 1307

   // **********setting time**************
// Wire.send(sendung, 8); //sec
 Wire.send(_sec); //sec
 Wire.send(_min); //min
 Wire.send(_hour);  //hour
 Wire.send(_day);  //day
 Wire.send(_date); //date
 Wire.send(_month);  //month
// Wire.send(_year);  //year

 Wire.endTransmission();    // stop transmitting

void loop()


 Wire.requestFrom(104, 6);    // request 6 bytes from slave ds1307
 while(Wire.available())    // slave may send less than requested
   digitalWrite(13,state); //LED on pin 13 to see if there is activity
   int c = Wire.receive();


delay (100);

thanks for help



Jun 04, 2007, 12:44 am Last Edit: Jun 04, 2007, 12:50 am by Daniel Reason: 1

check page 7 4 of the datasheet:

"Please note that the initial power on state of all registers is not defined.  Therefore it is important to
enable the oscillator (CH bit=0) during initial configuration. "

You could also check this page on using the Dallas DS1306.


Thanks for the fast reply,

I read that, bit 7 of register 00.
But isnt it the same as the "seconds" Register? So it will be set with the _sec value, which is set to 4 (binary 00000010) at the moment?
How to Adress the different registers, just by executing eg 3 times a Wire.send() line to acces the 3rd register?




not sure.. for inspiration, i would have a look at the  DS1306 tutorial.



Many 32 kHz crystals are not designed to operate at the 6 (or 12) pFd input C of the DS1307.

You might add a 20 pFd cap from each side of the crystal to GRD.

Your CH is being set to 0 which is correct.


Go Up