A program to read the DS2745 by means of the I2C bus.

Dependencies:   RTC mbed

Files at this revision

API Documentation at this revision

Comitter:
Ugly_Kid
Date:
Thu Oct 31 13:36:32 2013 +0000
Commit message:
Leitura do DS2745 GTACQUAPLUS

Changed in this revision

RTC.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RTC.lib	Thu Oct 31 13:36:32 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/RTC/#be9d058ee5c7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 31 13:36:32 2013 +0000
@@ -0,0 +1,78 @@
+#include "mbed.h"
+#include "RTC.h"
+
+Ticker reading_i2c;
+
+DigitalOut myled1(LED1);
+
+DigitalOut myled2(LED2);
+
+DigitalOut myled3(LED3);
+
+DigitalOut myled4(LED4);
+
+
+I2C i2c(p9, p10);
+ 
+const int addr = 0x90;
+Serial pc(USBTX, USBRX);
+int x;
+
+void read_i2c ()
+{
+    x = 0;
+}
+
+
+void ledFunction( void )
+{
+    if (myled3 == 0)
+        myled3 = 1;
+    else myled3 = 0;
+    //RTC::detach(RTC::Second);
+    time_t seconds = time(NULL);
+    printf("\n%s\n", ctime(&seconds));
+}
+ 
+int main() {
+    reading_i2c.attach(&read_i2c, 0.1);
+
+    set_time(1256729737);
+    tm t = RTC::getDefaultTM();
+    RTC::attach(&ledFunction, RTC::Second);
+
+    int iI2Cfreq = 100000; // bus frequency in Hz
+    i2c.frequency (iI2Cfreq); //set I2C frequency
+    //i2c1.frequency (iI2Cfreq); //set I2C frequency
+    pc.baud(115200);
+
+//    int i,j;
+    int j;
+    float z, k;
+    char cRegister[1];
+    char cData[2];
+//    char cData1[2];
+    cRegister[0] = 0x0E;
+    cData[0] = 0x00;
+    cData[1] = 0x00;
+    k = 0.0015625;
+ //   cData1[0] = 0x00;
+ //   cData1[1] = 0x00;
+    while (1) {
+        if (x == 0)
+        {
+            i2c.write(addr, cRegister, 1);
+            i2c.read(addr, cData, 2);
+//            i2c1.write(addr, cRegister, 1);
+//            i2c1.read(addr, cData1, 2);
+//            i = 256*(int)cData1[0]+(int)cData1[1];
+            j = 256*(int)cData[0] + (int)cData[1];
+            z = j;
+            z = (z * k)/0.02;
+//            z = 100 - ((j - i)/z * 100);
+//            printf("Regulador %X %X \t ACQUAPLUS %X %X \t Eficiencia %f%%\n", cData[0], cData[1], cData1[0], cData1[1], z);
+            printf("Corrente (mA) %.2f \n", z);
+            x = 1;
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Oct 31 13:36:32 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file