Simple RTC class based on DS1307. Emphasis on simple. Allows you to run at 100k or 400k Hz (for newer DS1307 capable devices). MapTime() allows you to set the time() service to the same as the RTC. Uses struct tm throughout so you can use traditional time functions for manipulation.

Dependents:   AdaFruit_RGBLCD

Revision:
13:1ccadbd4c1bd
Parent:
12:9e7a91c34083
Child:
14:d5b47ff12d17
--- a/RTclock.cpp	Wed Sep 03 06:01:13 2014 +0000
+++ b/RTclock.cpp	Wed Sep 03 06:22:51 2014 +0000
@@ -1,9 +1,10 @@
 #include "mbed.h"
 #include "RTclock.h"
 
-RTclock::RTclock(I2C & in_cI2C, EClockType in_eClockType)
+RTclock::RTclock(I2C & in_cI2C, uint8_t in_nAddress, EClockType in_eClockType)
     : m_bTwelveHour(false)
     , m_cI2C(in_cI2C)
+    , m_nAddress(in_nAddress)
     , m_eClockType(in_eClockType)
 {        
 }
@@ -74,8 +75,8 @@
 
 bool RTclock::read(uint8_t in_nAddress, char * out_pBuffer, int in_nLength)
 {
-    if (0 != m_cI2C.write(0xd0, (char *)&in_nAddress, 1)) return false;
-    if (0 != m_cI2C.read(0xd0, out_pBuffer, in_nLength)) return false;
+    if (0 != m_cI2C.write(m_nAddress, (char *)&in_nAddress, 1)) return false;
+    if (0 != m_cI2C.read(m_nAddress, out_pBuffer, in_nLength)) return false;
     
     return true;
 }
@@ -196,5 +197,5 @@
     for (size_t i = 0 ; i < in_nLength; i++)
         aBuffer[i + 1] = in_pBuffer[i];
 
-    return m_cI2C.write(0xd0, aBuffer, in_nLength + 1);
+    return m_cI2C.write(m_nAddress, aBuffer, in_nLength + 1);
 }