Distributed & Cognitive Systems Group / Mbed 2 deprecated Master_I2C

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
IMJESR
Date:
Tue Nov 03 19:43:07 2015 +0000
Commit message:
Commit inicial

Changed in this revision

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/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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Nov 03 19:43:07 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7cff1c4259d7
\ No newline at end of file