Dmitry Dzhafarkhanov / Mbed 2 deprecated Nucleo_I2C_Scaning

Dependencies:   mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 
00004 #define D_SDA                  I2C_SDA
00005 #define D_SCL                  I2C_SCL
00006 
00007 I2C i2c(D_SDA, D_SCL);
00008 
00009 Serial pc(SERIAL_TX, SERIAL_RX);
00010  
00011 char data [255];
00012 int i;
00013 int main()
00014 {
00015     pc.printf("started.. \n");
00016     // Scan for I2C devices that reply with ack
00017     for (i=0; i<=254; i=i+2) {
00018         if (i2c.read(i, &data[0], 1) ==0) 
00019         {
00020             pc.printf("I2C device detected at address=%2.2X\n\r", i);
00021         }
00022     }
00023     }