Your connections seem fine. Also, from the RS1337 datasheet, you can power the IC with both 5V and 3.3V. Both are within the IC's described recommended DC operating conditions.
If you have an oscilloscope handy, put the probe on X1 then on X2 (I never know which is the correct one, so I try them both, one at a time) and check if the crystal is oscillating. If you get a clean 32,768Hz square wave, then it's oscillating properly.
Also, you need to double-check whether you've followed the board layout restrictions regarding ground and signals going near the crystal pins, as per datasheet. I'm copying the relevant part below:
![Restrictions for board layout for DS1337](https://i.stack.imgur.com/HWvLh.png)
If there's a signal going near the crystal pins, the internal IC registers will get corrupted. Then you'll get all sort of weird symptoms. That may be the cause of your problem.
I got sloppy in one of my layouts with the DS1307 RTC and got similar problems. In my case, I could set the time, but the minutes register would decrease unit by unit, randomly.
If you're board doesn't follow the recommendations, one way of fixing it is to ground crystal case (like so: Is case grounding compulsory in typical 32.768kHz crystal for Real Time Clock?). That did the trick for me.
Edit: Looking again at your serial monitor printout, it looks like your code was not able to set the clock time. The time it's printing on serial is likely the time you tried to set, but failed. To me, that means that the I2C communication is not working properly. Maybe it's the device address that's wrong, or a problem with the wiring. I see that you have both pull-up resistors properly wired to SCL and SDA, so that's good. But I would double-check all that wiring.
To properly debug the I2C communication, you'll need an oscilloscope (like I did in this question of mine: What happens if I omit the pullup resistors on I2C lines?).
Edit 2: I still thinking you're not setting the time as you imagine. That's because the code below sets the values you defined into the C++ object called RTC
(which sits in the Arduino's RAM), but it fails to set them to the RTC IC:
void setup() {
RTC.start();
RTC.setSeconds(00);
RTC.setMinutes(00);
RTC.setHours(05);
RTC.setDays(06);
RTC.setMonths(3);
RTC.setYears(2014);
RTC.writeTime(); // I think this line is failing
// But the lines above succeed in setting the time into RAM (but not on the RTC)
}
Then, you print the time inside loop()
, but using the values in RAM:
void printTime(byte type) {
Serial.print(int(RTC.getMonths())); // these values come from RAM, not the RTC
Serial.print(int(RTC.getDays()));
Serial.print(RTC.getYears());
Serial.print(int(RTC.getDays()));
Serial.print(int(RTC.getHours()));
Serial.print(int(RTC.getMinutes()));
Serial.print(int(RTC.getSeconds()));
}
To confirm that, try running the code below:
...
void setup() {
RTC.start();
}
void loop() {
RTC.readTime();
printTime(0);
delay(1000);
}
If time isn't set, it will print a bunch of zeroes like 0/0/0 0:0:0
. If time is set, then it will print 3/6/2014 5:0:0
Best Answer
Seems like just a line omission from the datasheet. On the Pin Description section of Page 6
It seems to just skip a line stating that the pin is open drain and requires the external pull up, but then adds the same line afterwards, stating the pull up value. Looking at older versions of the datasheet, back when Maxim Integrated was Maxim-Dallas and even just Dallas Semi, the omission has always been there.
That said, the typical wiring diagram has always been correct, showing the pull up needed on both i2c lines, as the i2c standard requires.
As for the SQW/Out pin, the Pull Up is only required if you are using the line. It can be disabled in the rtc's settings (Or should I say, comes disabled, needs to be turned on). Having a pull up resistor on the line, when you are not going to use it, will waste energy, needlessly draining a battery (Slowly) in battery applications. As the datasheet says, this can be left floating, i.e. no pull up, if not needed. The Adafruit device breaks it out for your convenience if you do want to use it, but you need to add the pull up externally if you want to (or use the Arduino's internal pull-up option)