Distributed & Cognitive Systems Group / Mbed 2 deprecated Master_I2C

Dependencies:   mbed

Revision:
0:d9fc59e03646
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Nov 03 19:43:07 2015 +0000
@@ -0,0 +1,35 @@
+#include "mbed.h"
+
+I2C i2c(I2C_SDA, I2C_SCL);
+
+int main()
+{
+    int address = 0x52;
+    char data[2];
+    char switch_word;
+    switch_word=0xa0;
+    char recd_val;
+    
+i2c.frequency(400);
+    while(1) {
+        switch_word=switch_word|0x01;
+        i2c.start();
+//force a start condition
+        i2c.write(address);
+//send the address
+        i2c.write(switch_word);
+//send one byte of data, ie switch_word
+        i2c.stop();
+        wait(0.002);
+//receive a single byte of data, in correct I2C package
+        i2c.start();
+        i2c.write(address|0x01);
+//send address, with R/W bit set to Read
+        recd_val=i2c.read(address);
+//Read and save the received byte
+        i2c.stop();
+
+        printf("ACK: %d\n\r",recd_val);
+       
+    }
+}
\ No newline at end of file