Demo/test code: UART-I2C bridge. This program takes 3 byte data from terminal to write out in I2C bus. The 1st data is I2C address, second is register address and last is data for write.

Dependencies:   mbed

main.cpp

Committer:
okano
Date:
2010-03-15
Revision:
0:af8aa1f45fd2

File content as of revision 0:af8aa1f45fd2:

#include "mbed.h"

Serial   pc(USBTX, USBRX);    // tx, rx
I2C      i2c( p28, p27 );     // sda, scl

DigitalOut myled(LED1);

int main() {

    char    c[ 3 ];
    pc.printf("UART-I2C bridge\n");

    while(1) {
        pc.scanf( " %X %X %X", c, c + 1, c + 2 );
        printf( "%02X %02X %02X\n", *(c), *(c + 1), *(c + 2) );
        
        i2c.write( *c, c + 1, 2 );
    }
}