Saturday, October 18, 2014

Working with RTC with OpenCM9.04

RTC Grove D1307 & mini RTC DS3231
Both RTC modules use address 0x68 (default) for I2C exchange.

Modification is needed in the sample from SetTimeAndDisplay (arduino) by setting the following:

  1. // original function description deleted
  2. /****************************************************************************/
  3. #include <Wire.h>
  4. #include "DS1307.h"
  5. DS1307 clock;              //define a object of DS1307 class
  6. void setup()
  7. {
  8.  SerialUSB.begin();
  9.         Wire.begin(16,17);   //   specify the software defined I2C pins 16-SDA 17-SCL
  10.                                   // clock.begin(); comment out original begin() method otherwise
  11.                                   // pin21 (SDA) and pin20 (SCL) are declared in Wire
  12.  clock.fillByYMD(2014,10,18);//Jan 19,2013
  13.  clock.fillByHMS(15,15,30);//15:28 30"
  14.  clock.fillDayOfWeek(SAT);//Saturday
  15.  clock.setTime();//write time to the RTC chip
  16. }
  17. void loop()
  18. {
  19.  printTime();
  20. }
  21. /*Function: Display time on the serial monitor*/
  22. void printTime()
  23. {
  24.  clock.getTime();
  25.  SerialUSB.print(clock.hour, DEC);  // use SerialUSB class to print
  26.  SerialUSB.print(":");
  27.  SerialUSB.print(clock.minute, DEC);
 

No comments:

Post a Comment