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:
Sun Jun 02 09:59:39 2013 +0000
Child:
1:64274190e842
Commit message:
Initial Revision - not working yet.

Changed in this revision

Rtc_Ds1307.cpp Show annotated file Show diff for this revision Revisions of this file
Rtc_Ds1307.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rtc_Ds1307.cpp	Sun Jun 02 09:59:39 2013 +0000
@@ -0,0 +1,45 @@
+/* Rtc_Ds1307.cpp */
+
+#include "Rtc_Ds1307.h"
+
+#define _DEBUG 0
+
+
+#if (_DEBUG && !defined(TARGET_LPC11U24))
+#define INFO(x, ...) std::printf("[Rtc_Ds1307 : INFO]"x"\r\n", ##__VA_ARGS__);
+#define WARN(x, ...) std::printf("[Rtc_Ds1307 : WARN]"x"\r\n", ##__VA_ARGS__);
+#define ERR(x, ...) std::printf("[Rtc_Ds1307 : ERR]"x"\r\n", ##__VA_ARGS__);
+#else
+#define INFO(x, ...)
+#define WARN(x, ...)
+#define ERR(x, ...)
+#endif
+
+
+
+
+Rtc_Ds1307::Rtc_Ds1307(PinName sda, PinName scl)
+{
+    //  Create a new I2C object
+    m_rtc = new I2C(sda, scl);
+    if (m_rtc == NULL)
+        error("Rtc_Ds1307");
+}
+
+Rtc_Ds1307::~Rtc_Ds1307()
+{
+    if (m_rtc != NULL)
+        delete m_rtc;
+}
+
+bool Rtc_Ds1307::setTime(tm& time)
+{
+    INFO("Setting new time : %d:%d:%d\n", time.tm_hour, time.tm_min, time.tm_sec);
+    
+    return true;
+}
+
+bool Rtc_Ds1307::getTime(tm& time)
+{
+    return false;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rtc_Ds1307.h	Sun Jun 02 09:59:39 2013 +0000
@@ -0,0 +1,57 @@
+/* Rtc_Ds1307.h */
+/*
+Copyright (c) 2013 Henry Leinen (henry[dot]leinen [at] online [dot] de)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+#ifndef __RTC_DS1307_H__
+#define __RTC_DS1307_H__
+
+#include "mbed.h"
+
+
+/** Class Rtc_Ds1307 implements the real time clock module DS1307
+ *
+ * You can read the clock and set a new time and date.
+ * It is also possible to start and stop the clock.
+ * Rtc_Ds1307 allows you to display the time in a 12h or 24h format
+ */
+class Rtc_Ds1307
+{
+        I2C*    m_rtc;
+
+    public:
+        /** public constructor which creates the real time clock object
+         *
+         * @param sda : specifies the pin for the SDA communication line.
+         *
+         * @param scl : the pin for the serial clock
+         *
+         */
+        Rtc_Ds1307(PinName sda, PinName scl);
+        
+        ~Rtc_Ds1307();
+
+        bool getTime(tm& time);
+        
+        bool setTime(tm& time);        
+};
+        
+
+#endif // __RTC_DS1307_H__
\ No newline at end of file