Util used to scan for I2C devices
Fork of PRES11_I2C_Detect by
I2C program used to scan the I2C bus for connected devices
Import program
00001 #include "mbed.h" 00002 00003 //SDA , SCL 00004 I2C i2cBus(I2C_SDA, I2C_SCL); 00005 00006 int main() 00007 { 00008 i2cBus.frequency(100000); 00009 00010 printf("\r\n Scanning for I2C devices (addresses in hex)\r\n "); 00011 printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\r\n"); 00012 for (int i = 0; i < 128; i += 16) { 00013 printf("%02x: ", i); 00014 for(int j = 0; j < 16; j++) { 00015 // Skip unwanted addresses 00016 if (i+j < 0x3 || i+j > 0x77) { 00017 printf(" "); 00018 continue; 00019 } 00020 00021 if (!i2cBus.write(i+j<<1, NULL, 0)) 00022 printf("%02x ", i+j); 00023 else 00024 printf("-- "); 00025 00026 } 00027 printf("\r\n"); 00028 } 00029 } 00030
Diff: main.cpp
- Revision:
- 0:9e51d4453b53
- Child:
- 1:624dc0072a11
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Nov 09 13:21:03 2015 +0000 @@ -0,0 +1,29 @@ +#include "mbed.h" + +//SDA , SCL +I2C i2cBus(PB_9, PB_8); + +int main() +{ + i2cBus.frequency(100000); + + printf("\r\n Scanning for I2C devices (addresses in hex)\r\n "); + printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\r\n"); + for (int i = 0; i < 128; i += 16) { + printf("%02x: ", i); + for(int j = 0; j < 16; j++) { + // Skip unwanted addresses + if (i+j < 0x3 || i+j > 0x77) { + printf(" "); + continue; + } + + if (!i2cBus.write(i+j<<1, NULL, 0)) + printf("%02x ", i+j); + else + printf("-- "); + + } + printf("\r\n"); + } +}