demo program

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
okano
Date:
Fri May 29 06:20:17 2015 +0000
Commit message:
initial version

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	Fri May 29 06:20:17 2015 +0000
@@ -0,0 +1,28 @@
+#include "mbed.h"
+
+I2C i2c( p28, p27 );    //  SDA, SCL
+
+int main() {
+    char    a[ 2 ];
+    
+    a[ 0 ]  = 0x08; //  register address for write
+    a[ 1 ]  = 0x52; //  writing data
+        
+    char    w[ 1 ]; 
+    char    r[ 1 ]; //  buffer for read
+    
+    w[ 0 ]  = 0x08; //  register address for read
+    
+    while(1) {
+        //  writing
+        i2c.write( 0x02, a, 2 );
+        wait( 0.001 );
+        
+        //  reading
+        i2c.write( 0x02, w, 1 );
+        i2c.read( 0x02, r, 1 );
+        wait( 0.003 );
+
+        printf( "register read : 0x%02X\r\n", r[ 0 ] );
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri May 29 06:20:17 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/cbbeb26dbd92
\ No newline at end of file