Neng-Hong Zeng / Mbed 2 deprecated i2c_detect

Dependencies:   mbed

Fork of i2c_detect by Rune Langoy

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 //SDA , SCL
00004 //I2C i2cBus(I2C_SDA, I2C_SCL);
00005 I2C i2cBus(p9, p10);
00006 
00007 int main()
00008 {
00009     i2cBus.frequency(100000);
00010 
00011     printf("\r\n Scanning for I2C devices (addresses in hex)\r\n ");
00012     printf("    0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f\r\n");
00013     for (int i = 0; i < 128; i += 16) {
00014         printf("%02x: ", i);
00015         for(int j = 0; j < 16; j++) {
00016             // Skip unwanted addresses
00017             if (i+j < 0x3 || i+j > 0x77) {
00018                 printf("   ");
00019                 continue;
00020             }
00021 
00022             if (!i2cBus.write(i+j<<1, NULL, 0))
00023                 printf("%02x ", i+j);
00024             else
00025                 printf("-- ");
00026 
00027         }
00028         printf("\r\n");
00029     }
00030 }
00031