Working Version of the Real Time Clock module DS1307.

Dependents:   Rtc_Ds1307_Sample TAREA_5_PROCESADORES Rtc_Ds1307_lcd_alarma Rtc_Ds1307_Reloj_con_alarma_aplazable ... more

This is my implementation of the DS1307.

I plan to add functionality which will make use of the OSC Input and which will increment the time continuously. A query to the module will then only have to be made when the MBED has been powered down.

Files at this revision

API Documentation at this revision

Comitter:
leihen
Date:
Wed Jun 26 21:05:46 2013 +0000
Parent:
8:d0e66fa78e79
Commit message:
Changed initialization

Changed in this revision

Rtc_Ds1307.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r d0e66fa78e79 -r 5627b407e097 Rtc_Ds1307.cpp
--- a/Rtc_Ds1307.cpp	Sun Jun 23 19:24:57 2013 +0000
+++ b/Rtc_Ds1307.cpp	Wed Jun 26 21:05:46 2013 +0000
@@ -2,7 +2,7 @@
 #include "Rtc_Ds1307.h"
 
 #ifndef DEBUG
-#define DEBUG
+//#define DEBUG
 #endif
 #include "debug.h"
 
@@ -205,17 +205,19 @@
 RtcCls::RtcCls(PinName sda, PinName scl, PinName sqw, bool bUseSqw)
     : Rtc_Ds1307(sda, scl), m_sqw(sqw), m_bUseSqw(bUseSqw), m_bAlarmEnabled(false), m_alarmfunc(NULL)
 {
+    Time_rtc t;
+    //  query time from device
+    getTime(t);
+    //  sync the time with MBED RTC
+    struct tm now = {t.sec, t.min, t.hour, t.date, t.mon-1, t.year-1900};
+    m_time = mktime(&now);
+    set_time(m_time);
+    
     //  Only register the callback and start the SQW if requested to do so. Otherwise the system
     //  will use the MBED built-in RTC.
     if (m_bUseSqw) {
-        Time_rtc t;
         //  start the wave
         setSquareWaveOutput(true, RS1Hz);
-        //  query time
-        getTime(t);
-        struct tm now = {t.sec, t.min, t.hour, t.date, t.mon-1, t.year-1900};
-        m_time = mktime(&now);
-        set_time(m_time);
         //  register callback from now on the time will be maintained by the square wave input
         m_sqw.rise(this, &RtcCls::_callback);
     }