Jonathan Goret / Mbed 2 deprecated i2c_scan

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(PB_9, PB_8);
00004 Serial debug(SERIAL_TX, SERIAL_RX);
00005  
00006 char data [255];
00007 int i;
00008 int main()
00009 
00010 {
00011     debug.format(8,Serial::None,1); 
00012 debug.baud(115200); 
00013     debug.printf("started.. \n");
00014     // Scan for I2C devices that reply with ack
00015     for (i=0; i<=254; i=i+2) {
00016         if (i2c.read(i, &data[0], 1) ==0) 
00017         {
00018             debug.printf("I2C device detected at address=%2.2X\n\r", i);
00019         }
00020     }
00021 }