RTC DS1307 + UNO not working, pls help!!!

To be more detailed, I'm testing my RTC ds1307 i just built recently and tried the sample coding with a little modication. As a result, the serial monitor shows that the DS1307 is running but the time and date did not change and remains the same. Does anyone has any idea on this?

// 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(19200);
#ifdef AVR
  Wire.begin();
#else
  Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
  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(2014,6,14,23,33,0));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
}

void loop () {
    DateTime now = rtc.now();
    
    Serial.print(now.year());
    Serial.print('/');
    Serial.print(now.month());
    Serial.print('/');
    Serial.print(now.day());
    Serial.print(' ');
    Serial.print(now.hour());
    Serial.print(':');
    Serial.print(now.minute());
    Serial.print(':');
    Serial.print(now.second());
    Serial.println();
    
  
    
    Serial.println();
   delay(1000);
}

http://datasheets.maximintegrated.com/en/ds/DS1307.pdf

Maybe your crystal isn't working.

void setup() 
{
  Serial.begin(9600);

  RTC.begin();
  //To set clock, remove the // on the RTC.adjust line below
  //Upload sketch, then replace // and upload again.
 // RTC.adjust(DateTime(__DATE__, __TIME__));
}

Follow instructions above.
You must upload twice.
The 2nd upload with the // replaced prevents the time from reloading the 1st compiled time,
when the Arduino is reset.

I had the same problem, and I solved it (I believe). I use a TinyRTC and I saw that when I pass the finger tips over the connection holes in the module, the module momentarily works. After that I add a resistor of approximately 1k between the Vcc and the SDA and SCL pins. I've never notice more problems.

I tried the pull resistors and still doesn't work. Oh, how do you check if the crystal is faulty?

You are using a module or the chip it self?
Do you have an oscilloscope?
I think that you can verify the signal that is coming out from the SQ pin.

EDIT: To have some signal coming out from the SQ pin you must have to config the SQ enable bit of the DS1307, so if you are not able to communicate with the device, I believe, that not work for you. But if, like you said in the first post, you are able to communicate with the device, you can write the value 0x90 to the register 0x07, and attach one LED and one resistor to the SQ pin. To write the value to the device I modify the "RTClib.cpp", modifying the begin() method:

uint8_t RTC_DS1307::begin(void) {
  i=7;
  Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(i);
  Wire.write(0x90);	
  Wire.endTransmission();
  i=0;
  return 1;
}

When you attach the LED to the pin, like I said, you must see the LED blinking at the frequency of 1Hz (1 time per second).

I know this is an old thread but I had the same problem and arrived here by Googling.

My problem was that I was using a 32.768Mhz crystal instead of 32.768Khz!
In my defence the crystal just says 32.768 :slight_smile:

nogginthenog:
My problem was that I was using a 32.768Mhz crystal instead of 32.768Khz!

Where on earth would you get such a peculiar value? 32.768Khz is standard because it divides easily to 1 Hz. I cannot see a clear use for 32.768Mhz :astonished: