Rune Langoy / Mbed 2 deprecated i2c_detect

Dependencies:   mbed

Fork of PRES11_I2C_Detect by EL-POM1001

Files at this revision

API Documentation at this revision

Comitter:
rlanghbv
Date:
Mon Nov 09 13:21:03 2015 +0000
Child:
1:624dc0072a11
Commit message:
First comit

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /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");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Nov 09 13:21:03 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11
\ No newline at end of file