An I2C Scanner, to test that your I2C can be detected. Works with the NRF51 Development Kit.

Dependencies:   mbed-src-nrf51822

Revision:
0:839b7264c387
Child:
1:117c1bb3ce43
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jun 09 11:06:51 2016 +0000
@@ -0,0 +1,41 @@
+#include "mbed.h"
+#include "wire.h"
+ 
+#define SCL         7  
+#define SDA         30
+ 
+TwoWire Wire = TwoWire(NRF_TWI0);
+
+int main(void)
+{
+    Wire.begin(SCL, SDA, TWI_FREQUENCY_100K);
+    printf("IIC Demo Start \r\n");
+
+    while(1)
+    {
+        int nDevices = 0;
+        for(int address = 1; address < 127; address++ ) 
+        {
+            int error = -1;
+            Wire.beginTransmission(address << 1);
+            Wire.write(0x00);
+            error = Wire.endTransmission();
+                       
+            if (error == 0)
+            {
+              printf("I2C device found at address 0x%X %d \n\r", address, error); //Returns 7-bit address
+              nDevices++;
+            }
+        }
+        if (nDevices == 0)
+        {
+            printf("No I2C devices found\n\r");
+        }
+        else{}
+        printf("\ndone\n\r");
+        
+        wait(2);           // wait 2 seconds for next scan
+          
+    }
+}
+ 
\ No newline at end of file