DS1307 troubleshooting

Good afternoon, everyone. I'm trying to interface a DS1307 real time clock with an Arduino. I'm (still) working on a sprinkler timer...

Initially, everything works fine. I get the I2C RTC connected to SDA, SCL, ground, Vcc, ground Vbat if I'm not using the battery, add the crystal and I'm up and running. I've done this several times, now, with two different DS1307 chips. I'm able to set and retrieve the time, enable the 1Hz square wave so that I get an LED flashing every second, and generally my system's working as designed. Then, (most recently, anyway) I removed the jumper from Vbat to ground and hooked in a CR2032 coin cell providing a little over 3V (properly connecting the negative end of the battery to the common ground) and then I can no longer communicate with the RTC. If I then take baby steps backwards, removing the battery, adding the jumper back in, etc., I still can't talk to the RTC. If I desolder (grrr) the RTC chip from my circuit board and stick it on a breadboard with another Arduino, it still works. It seems like there's something that's keeping the RTC from returning from its self-imposed silence until I release it from the bonds holding it to my circuit board! This is maddening; I'm this >< close to finishing my project and the RTC starts giving me the silent treatment. I just can't make sense of it. Even removing the AVR chip doesn't reset the RTC. I've built two separate circuit boards (I'm building this AVR+RTC system on one of the Evil Mad Scientist AtmegaXX8 target boards), and they're both doing the same thing. It'll work initially, but then I do something silly like hook up the battery and it all goes pear-shaped.

Has anyone else experienced anything like this? Any spells, incantations, or funny dances I could try? I just want to finish this project and move on to something else!

Thanks,
B

Has anyone else experienced anything like this? Any spells, incantations, or funny dances I could try? I just want to finish this project and move on to something else!

Without seeing your complete wiring it's hard to guess what is happening. Just to clear up how the Batt voltage works, it does not power the whole chip, it just maintains the oscillator and basic counters needed to maintain the time until VCC voltage is next applied. I2C communications can only work while there is +5vdc on the Vcc terminal. Also while in the 'battery save' mode you probably don't want the 1hz signal driving a LED or even a pull up resistor as that will discharge the small battery much faster then the design calls for. The battery only needs to supply micro amps of current during the power off period and any electrical load on the clock signal output will increase the battery current significantly.

Any of this help?

Lefty

Check for solder bridges, bad solder joints, etc on the board? Sounds like it may be board related if the IC works elsewhere.

You have heard of sockets, right? :slight_smile:

-j

Thanks for the reply, Lefty. I hadn't realizes that SQW/OUT was still active when running just on Vbat. I'd only hooked the LED up there for testing purposes, but I do see where that would have caused problems in the future. :slight_smile: I don't think there's a way around the pull-up resistor, however; the output will float without it, which could cause spurious interrupts on the AVR. A very large pull-up would minimize the current draw. I think the current drawn by the DS1307 is actually measured in nano-amps when running on battery!

As far as wiring goes, I'm basically using the same schematic as SparkFun shows for their breakout board:

I added 10k pull-up resistors to SDA and SCL (and have disabled the internal pull-ups in twi.c), but that hasn't made a difference.

Check for solder bridges, bad solder joints, etc on the board? Sounds like it may be board related if the IC works elsewhere.

I've had both ICs on two different target boards, and had the same result every time. It's maddening!

You have heard of sockets, right?

Smart aleck. :wink: Yes, I always use sockets for the AVRs, but the DS1307s aren't supposed to be so damn finicky!

I may have misled on the pull-up or LED wired to the clock output pin. It's a open drain output so the current drawn will be from whatever is powering the other side of the LED or pull-up, not the battery.

Lefty

The only time I had a problem with the 1307 not ticking was related to Vbat. Is there any way the Vbat connection could be bad, or battery dead, or backwards or something? Vbat must be either ~3V or grounded or it won't tick.

-j

Ummm... I'd have to review the datasheet again but I'm pretty sure the DS1307 goes into low power mode when it senses it's on the battery power source. In this mode the oscillator keeps running to keep the time, but the chip won't respond to the I2C bus.

From the datasheet:

When VCC falls below 1.25 x VBAT, the device terminates an access in progress and resets the device address counter. Inputs to the device will not be recognized at this time to prevent erroneous data from being written to the device from an out-of-tolerance system. When VCC falls below VBAT, the device switches into a low-current battery-backup mode. Upon power-up, the device switches from battery to VCC when VCC is greater than VBAT +0.2V and recognizes inputs when VCC is greater than 1.25 x VBAT.

I also reading about this on some Dallas Semiconductor/Maxim tech note regarding battery backup and RTC's.

Vbat is like 3.1V. It seems like connecting the battery causes the problem, but even after removing it and grounding the Vbat pin, it still won't tick. It's not even that it won't tick, it won't even respond.

With the (power-hungry) LED connected directly to SQW/OUT (with an appropriate resistor, and pulled up to +5V), the LED comes on once the chip receives power; this is the default configuration. The power-on state of the chip is to hold SQW/OUT low, so the LED lights up. For troubleshooting purposes, once I can talk to the chip, I enable the 1Hz square wave, which makes the LED flash.

Is it some sort of sequence issue? i.e., do you connect Vbat to 3V or to GND before applying power to Vcc?

Is the crystal grounded on the board? IIRC the data sheet recommends a separate unconnected ground plane for it. Not sure if connecting it to the board ground would cause a problem.

I don't know if these matter, just shooting wild... I've put 1307s on at least half a dozen boards, besides breadboard prototypes, and have had no problems (but I've never used the square wave output, either).

-j

I think my DS1307s are just haunted. >:(

I started experiencing the problem before I tried using the SQW/OUT; that just proved to be helpful in showing that the chip is alive (I've been running without serial output, at times).

The crystal is not grounded. I'm working on perfboard/stripboard and there's no ground plane. Can I just solder a lead to the crystal and tie that to ground?

Sequence-wise, I've tried everything. :slight_smile: The proper sequence, as I see it, is to connect the battery (or ground Vbat) before applying +5V to Vcc. This will work initially; then if I de-power everything and hook up the battery, the IC is kaput.

The data sheet says:-

The DS1307 has a
built-in power-sense circuit that detects power failures
and automatically switches to the backup supply.

So have you tried connecting up the battery and then removing the power. I am not sure if it will start with just the battery but it sounds like it will keep it going once started.

Sounds like your crystal is OK - my point was maybe it shouldn't be tied to ground, but yours isn't, so nevermind.

I don't have a clue at this point.

-j

That makes two of us. Oh, well. ::slight_smile: