demo program

Dependencies:   mbed

Revision:
0:236c04f081b4
--- /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 ] );
+    }
+}