Sunday, March 21, 2010

Wiseduino with DS1337

DS1337 is another real time clock (RTC) from Maxim, closely resembling DS1307 that comes with the Wiseduino kit.

The main difference between these two chips is the ability of DS1337 to handle (set, trigger) an alarm. Otherwise, both have similar pin configurations, both "talk" I2C, and both use a 3V coin battery (DS1307 only as backup, DS1337 as the only power source).

Many others have included DS1337 on their boards and wrote libraries for this chip. I thought I should give it a try myself, especially because of the alarm capability. The easiest way was to modify an Wiseduino board, by cutting 3 traces and adding 2 wires, as shown in this image:

The cuts are shown with yellow lines, the wires are light blue. The rightmost cut is on the back of the board.

Updated Apr 17/2010
After I started the actual work, I realized that, since DS1337 is powered by the 3V coin battery, voltage level adapters (on SCL and SDA lines) need to be used between the clock and a 5V-powered Wiseduino. So I decided to power Wiseduino with 3V as well (2xAA batteries). This means the frequency cannot be 16MHz (according to ATmega168/328 datasheet); so I installed an 8MHz resonator instead. So far so good. I am able to upload the DS1337 sketch and read back the time. Current consumption is a under 5mA.

Here are a few other things I did to make this work:
  • on Wiseduino, I am using an ATmega168 with the bootloader, instead of the 328;
  • I changed boards.txt to accommodate the 8MHz working frequency:
  • tried unsuccessfully JLuciani's DS1337 library; it seems to require/use a different set of "wire" files than those coming with Arduino IDE 18; confusion ensues; files and functions need to be renamed etc etc; I just gave up;
  • tried, with limited success, xSmurf's DS1337 library; there seem to be multiple versions of the DS1337 class (and header), no sample sketch that uses the class; I had to eliminate some alarm-related stuff, define some macros etc. In the end, I have a simplified version working;
  • to upload the sketch to the board, I used the 3V3 version of the FTDI breakout from sparkfun (the 5V has the signal voltages too high).
Next steps:
  • put the microcontroller to sleep when time is not read (this will reduce the consumption to micro amps, hopefully);
  • implement the alarm functionality, with interrupts.

Conclusion DS1307 vs DS1337:
  • DS1337 should be used in a 3V3 environment; it is not meant to be mixed with 5V signals;
  • DS1337 libraries I looked at so far are pretty finicky compared to DS1307 libraries;
  • an equivalent of (that is, as easy to use as) DS1307 for 3V3 is DS1340 (used by JeeLabs in their JeeNode boards).


  1. Great stuff, thanks for the work.

    I am hoping to attach the DS1337 alarm function to one of the arduino's interrupts, but couldn't seem to find a pre-built DS1337 library. I am not quite competent to write my own...

    Any luck getting the alarm function to work?

  2. Not yet, but I am working on it. I actually need that functionality for my next analog watch.

  3. I am working on an application using the DS1337, and I have a question about your conclusion comparing the two chips. Why do you say the 1337 is a 3.3v device and not to be mixed with 5v signals? The datasheet clearly states the IC can operate normally from 1.8v to 5.5v. Am I missing something?

  4. Kevin,
    It's been a while since I wrote this.
    You are right, DS1337 can be powered by 5V. But, unlike DS1307, it does not have provisions for a battery backup. If you power the chip from the main source as your Arduino, once the power goes down, your setting (time etc) are lost.
    This is the main and only reason for my first conclusion enumerated above: just power the DS1337 from an independent, small (because the current taken is uA) source. Of course this source could be another 5V battery, but that may not be as practical as a small 3V coin battery.
    You would need to use an logic level adapter between the 3V RTC chip and a 5V Arduino. Therefore, I concluded that a more practical solution would be to power the DS1337 with 3V, the Arduino with 3V3 and connect them directly.
    Does this makes sense to you?