i2c scan peripheriques

Dependencies:   mbed

main.cpp

Committer:
johnylafleur
Date:
2015-03-31
Revision:
0:b4f549ac73a6

File content as of revision 0:b4f549ac73a6:

#include "mbed.h"
 
I2C i2c(PB_9, PB_8);
Serial debug(SERIAL_TX, SERIAL_RX);
 
char data [255];
int i;
int main()

{
    debug.format(8,Serial::None,1); 
debug.baud(115200); 
    debug.printf("started.. \n");
    // Scan for I2C devices that reply with ack
    for (i=0; i<=254; i=i+2) {
        if (i2c.read(i, &data[0], 1) ==0) 
        {
            debug.printf("I2C device detected at address=%2.2X\n\r", i);
        }
    }
}