demo program

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 I2C i2c( p28, p27 );    //  SDA, SCL
00004 
00005 int main() {
00006     char    a[ 2 ];
00007     
00008     a[ 0 ]  = 0x08; //  register address for write
00009     a[ 1 ]  = 0x52; //  writing data
00010         
00011     char    w[ 1 ]; 
00012     char    r[ 1 ]; //  buffer for read
00013     
00014     w[ 0 ]  = 0x08; //  register address for read
00015     
00016     while(1) {
00017         //  writing
00018         i2c.write( 0x02, a, 2 );
00019         wait( 0.001 );
00020         
00021         //  reading
00022         i2c.write( 0x02, w, 1 );
00023         i2c.read( 0x02, r, 1 );
00024         wait( 0.003 );
00025 
00026         printf( "register read : 0x%02X\r\n", r[ 0 ] );
00027     }
00028 }