i2c

Dependencies:   mbed

Fork of Serial_HelloWorld_Mbed by mbed official

Revision:
2:24f2636c2915
Parent:
1:560b8ced44df
--- a/main.cpp	Sun Sep 21 05:44:05 2014 +0000
+++ b/main.cpp	Fri Mar 27 14:52:54 2015 +0000
@@ -1,10 +1,42 @@
 #include "mbed.h"
  
 Serial pc(USBTX, USBRX); // tx, rx
- 
+I2C i2c(p28, p27);
+const int addr_r = 0xA9; //Read of EEPROM 10101001
+const int addr_w = 0xA8; //Write of EEPROM 10101000
+//const int freq = 300000;
+
+
 int main() {
-    pc.printf("Hello World!\n\r");
-    while(1) {
-        pc.putc(pc.getc() + 1); // echo input back to terminal
-    }
+    pc.printf("EEPROM operation util\n\r");
+    char cmd[] = "aahello!!!";
+    cmd[0]=0xAA;
+    cmd[1]=0x12;
+    char buffer[8];
+
+
+    //i2c.frequency(freq);
+    pc.printf("Selection of i2c offset ");
+    if(i2c.write(addr_w,cmd,2,true)==0) {pc.printf("succeed"); } 
+    else pc.printf ("failed");
+    i2c.read(addr_r, buffer, 8, false);
+ /*   pc.printf("\n\rread 8 bytes: %s\n\r", buffer);
+    wait(0.5);
+    pc.printf("trying to write: %s ",cmd);
+    if(i2c.write(addr_w,cmd,10,false)) printf("succeed"); 
+    else printf ("failed");
+    wait(0.5);
+    pc.printf("Selection of i2c offset ");
+    if(i2c.write(addr_r,cmd,2,true)==0) {printf("succeed"); }
+    else printf ("failed");
+    i2c.read(addr_r, buffer, 8, true);
+    i2c.stop();
+    pc.printf("\n\rread 8 bytes: %s\n\r", buffer);
+  */  
+    
+    
+    
+    while(1)
+    {
+    }    
 }
\ No newline at end of file