Util used to scan for I2C devices

Dependencies:   mbed

Fork of PRES11_I2C_Detect by EL-POM1001

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 

Files at this revision

API Documentation at this revision

Comitter:
rlanghbv
Date:
Tue Nov 10 13:29:27 2015 +0000
Parent:
0:9e51d4453b53
Commit message:
first commit

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 9e51d4453b53 -r 624dc0072a11 main.cpp
--- a/main.cpp	Mon Nov 09 13:21:03 2015 +0000
+++ b/main.cpp	Tue Nov 10 13:29:27 2015 +0000
@@ -1,7 +1,7 @@
 #include "mbed.h"
 
 //SDA , SCL
-I2C i2cBus(PB_9, PB_8);
+I2C i2cBus(I2C_SDA, I2C_SCL);
 
 int main()
 {
@@ -27,3 +27,4 @@
         printf("\r\n");
     }
 }
+