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.
Revision 8:d0e66fa78e79, committed 2013-06-23
- Comitter:
- leihen
- Date:
- Sun Jun 23 19:24:57 2013 +0000
- Parent:
- 7:dca20be3ef38
- Child:
- 9:5627b407e097
- Commit message:
- Totally working now. Will set the MBED RTC once the class has been created. Can use the Ds1307 clock to Keep the System time up to date.
Changed in this revision
Rtc_Ds1307.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Rtc_Ds1307.cpp Sun Jun 23 18:48:59 2013 +0000 +++ b/Rtc_Ds1307.cpp Sun Jun 23 19:24:57 2013 +0000 @@ -2,7 +2,7 @@ #include "Rtc_Ds1307.h" #ifndef DEBUG -//#define DEBUG +#define DEBUG #endif #include "debug.h" @@ -213,8 +213,9 @@ setSquareWaveOutput(true, RS1Hz); // query time getTime(t); - struct tm now = {t.sec, t.min, t.hour, t.date, t.mon, t.year}; + 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); } @@ -222,13 +223,14 @@ void RtcCls::_callback(void) { +// INFO("Tick!"); // Simply increase the number of seconds m_time++; - if (m_bAlarmEnabled && (m_time == m_alarmTime)) { - if (m_alarmfunc != NULL) - m_alarmfunc(); - m_bAlarmEnabled = false; - } +// if (m_bAlarmEnabled && (m_time == m_alarmTime)) { +// if (m_alarmfunc != NULL) +// m_alarmfunc(); +// m_bAlarmEnabled = false; +// } } time_t RtcCls::getTime() @@ -237,8 +239,12 @@ if (!m_bUseSqw) { Time_rtc t; getTime(t); - struct tm now = {t.sec, t.min, t.hour, t.date, t.mon, t.year}; + struct tm now = {t.sec, t.min, t.hour, t.date, t.mon-1, t.year-1900}; m_time = mktime(&now); + INFO("getting time %02d.%02d.%04d %02d:%02d:%02d Ticks=%08lx", t.date, t.mon, t.year, t.hour, t.min, t.sec, m_time); + } + else { + INFO("getting time Ticks=%08lx", m_time); } return m_time; } @@ -253,9 +259,10 @@ tim.min = now->tm_min; tim.hour = now->tm_hour; tim.date = now->tm_mday; - tim.mon = now->tm_mon; + tim.mon = now->tm_mon+1; tim.year = now->tm_year + 1900; tim.wday = now->tm_wday +1; setTime( tim, true, true); + set_time(t); }