Keeping track of time on a netduino using a Maxim DS1307 real-time clock

Dali - Montre Molle

The ARM 7 processor in the netduino features an internal low-power oscillator and a programmable clock signal generator for its own timing needs but it is not intended to be a dedicated, battery-backed, date / time keeping system like the Maxim DS1307 real-time clock.






The DS1307 has the following features:

  • Real-Time Clock (RTC) Counts Seconds, Minutes, Hours, Date of the Month, Month, Day of the week, and Year with Leap-Year Compensation Valid Up to 2100
  • 56-Byte, Battery-Backed, General-Purpose RAM with Unlimited Writes (very useful on a netduino to store configuration data!)
  • I²C Serial Interface
  • Programmable Square-Wave Output Signal
  • Automatic Power-Fail Detect and Switch Circuitry
  • Consumes Less than 500nA in Battery-Backup Mode with Oscillator Running.

Being a popular chip, you can easily find complete, ready-to-go, real-time clock modules using it: Sparkfun has one and so does Futurlec among others.

Connecting the clock module to a netduino over I2C is trivial:

  • netduino analog pin 4 -> SDA pin on the clock
  • netduino analog pin 5 -> SCL pin on the clock
  • netduino 5v pin -> Vcc pin on the clock
  • netduino GND pin -> GND pin on the clock

A 1 or 2K pull-up resistor connected to 5v is only required when using the square-wave generation function on the clock (INT pin).

The square-wave function can generate frequencies at 1Hz, 4kHz, 8kHz and 32kHz and is useful in scenarios when a device relies on an external clock signal entirely, when a program relies on timely interrupts to do some work or to come back from a low-power sleep mode.

Here’s the oscilloscope output that I used to test the square-wave generation function:

1hz frequency

4 kHz frequency

8 kHz frequency

32 kHz frequency

To easily interface the DS1307 with the netduino, I wrote a C# driver which supports all of the chip’s features as I was unable to find one: most of the C# code out there appears to only support the date / time functions of the DS1307. You can find the driver and the test code here.

Happy hacking!



  1. Javad · September 1, 2013

    I am trying to use your code in a Netduino Plus 2, NET MF 4.2 with the wiring you have proposed. but it fails on any call to the I2CDevice. Would you please help me make it running.

    • Fabien Royer · September 1, 2013

      Hi Javad,

      I’m sorry, but I am no longer involved with anything Netduino-related.
      As far as the I2C communication issue goes: make sure that you have at least 1.8K ohm pull-ups on SDA and SCL and a 5v supply. If it doesn’t work, check SDA and SCL with a logic analyzer.

      I hope this helps.

      Best regards,

      • Javad · September 3, 2013

        thanks a lot, I’ll give it a try this weekend

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s