You are viewing an older revision! See the latest version

seeed grove RTC

Overview

The Seeed Grove RTC module is just one of over 50 prototyping modules in the Grove series. You can visit the Grove Wiki page to see all the modules offered: http://www.seeedstudio.com/wiki/GROVE_System

You may wonder why you would want to use a RTC module when the mbed already has a built in RTC. The primary reason is that the mbed consumes 27-30uA from the RTC battery whereas the DS1307 consumes only 300-500nA while on battery.

Grove RTC module

/media/uploads/STImbed/_scaled_dscn0447.jpg /media/uploads/STImbed/_scaled_dscn0442.jpg

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, Nonvolatile (NV)RAM for Data Storage
  • I2C Serial Interface
  • 5V DC supply
  • Programmable Square-Wave Output Signal
  • Automatic Power-Fail Detect and Switch Circuitry
  • Consumes Less than 500nA in Battery-Backup Mode with Oscillator Running
  • It uses a 3V Lithium cell battery (CR1225)

Additional Resources

http://www.seeedstudio.com/wiki/Grove_-_RTC Wiki page on the module

http://www.seeedstudio.com/wiki/images/9/9b/DS1307.pdf Datasheet on the DS1307 RTC

http://www.maxim-ic.com/datasheet/index.mvp/id/2688 Maxim webpage on the DS1307 RTC

http://www.maxim-ic.com/datasheet/index.mvp/id/2688/t/do#Data%20Sheet Collection of application notes

Control Register

/media/uploads/STImbed/ds1307control.jpg

Code

Fortunately Phillip Smith had already created a library for the DS1307 that works fine with the Grove RTC module. You can find his library here: http://mbed.org/users/harrypowers/libraries/DS1307/mc3r6y

Here is example code from Phillip's library page that I tested the Grove RTC module with:

// show how the DS1307 class works
 #include "ds1307.h"
 #include "mbed.h"

 Serial pc(USBTX, USBRX); // tx, rx  for debug and usb pc comunications

 DS1307 my1307(p9,p10); // start DS1307 class and give it pins for connections of the DS1307 device

 int sec = 0;
 int min = 0;
 int hours = 0;
 int day = 0;
 int date = 0;
 int month = 0;
 int year = 0;

 void test_rw(int test) {
     if (test == 0) pc.printf("Last R/W operaion passed!\n\r");
     else pc.printf("Last R/W operation failed!\n\r");
 }

 int main() {
     int junk = 0;

     sec = 24;       // 24 seconds
     min = 13;       // 13 min
     hours = 13;     // 1 pm
     day = 4;        // wednesday
     date = 20;      // June 20
     month = 6;
     year = 12;      // 2012
                     // set time to these values on the ds1307 connected device

     test_rw(my1307.settime( sec, min, hours, day, date, month, year));
     pc.printf("seconds set are %.2D \n\r",sec);
     pc.printf("min set are %.2D \n\r",min);
     pc.printf("hour set are %.2D \n\r",hours);
     pc.printf("day set are %.2D \n\r",day);
     pc.printf("date set are %.2D \n\r",date);
     pc.printf("month set are %.2D \n\r",month);
     pc.printf("year set are %.2D \n\r",year);
     wait(3);
                     // now read the time of the DS1307 device and see what time it is
                     // note that because of the 3 second wait this time should be 3 seconds past what it was set to earlier

     test_rw(my1307.gettime( &sec, &min, &hours, &day, &date, &month, &year));
     pc.printf("seconds read are %.2D \n\r",sec);
     pc.printf("min read are %.2D \n\r",min);
     pc.printf("hour read are %.2D \n\r",hours);
     pc.printf("day read are %.2D \n\r",day);
     pc.printf("date read are %.2D \n\r",date);
     pc.printf("month read are %.2D \n\r",month);
     pc.printf("year read are %.2D \n\r",year);

     junk = 0x39;                            // just a junk value do read and write test to DS1307 ram
     test_rw(my1307.write( 0x20, junk));     // this should write the value of junk to register 0x20 (a ram location) in the ds1307.
     pc.printf("Value written to register 0x20 %.2X \n\r",junk);
     junk = 0;                               // clear junk to show that when the register is read from the correct value is obtained
     test_rw(my1307.read( 0x20, &junk));     // this should read register 0x20
     pc.printf("Value read from register 0x20 %.2X \n\r",junk);
 }

All wikipages