00001 // I2CU - Search for devices on an I2C bus00002 // Copyright (c) 2009, sford00003 // Released under the MIT License: http://mbed.org/license/mit00004 //00005 // Goes through each device address, seeing if it gets a response00006 // - for every device if finds, it prints the 8-bit address00007 // - if the program hangs, the bus isn't working (check pull-ups etc)00008 // - if it doesn't find your device, check power/bus wiring etc00009
00010 #include "mbed.h"00011
00012 I2C i2c(p9, p10); // sda, scl00013
00014 int main() {
00015 printf("I2CU! Searching for I2C devices...\n");
00016
00017 int count = 0;
00018 for (int address=0; address<256; address+=2) {
00019 if (!i2c.write(address, NULL, 0)) { // 0 returned is ok00020 printf(" - I2C device found at address 0x%02X\n", address);
00021 count++;
00022 }
00023 }
00024 printf("%d devices found\n", count);
00025 }