Simon Ford
/
I2CU
Revision 0:4f78cdfc99de, committed 2009-09-03
- Comitter:
- simon
- Date:
- Thu Sep 03 21:51:26 2009 +0000
- Commit message:
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 |
diff -r 000000000000 -r 4f78cdfc99de main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Sep 03 21:51:26 2009 +0000 @@ -0,0 +1,25 @@ +// I2CU - Search for devices on an I2C bus +// Copyright (c) 2009, sford +// Released under the MIT License: http://mbed.org/license/mit +// +// Goes through each device address, seeing if it gets a response +// - for every device if finds, it prints the 8-bit address +// - if the program hangs, the bus isn't working (check pull-ups etc) +// - if it doesn't find your device, check power/bus wiring etc + +#include "mbed.h" + +I2C i2c(p9, p10); // sda, scl + +int main() { + printf("I2CU! Searching for I2C devices...\n"); + + int count = 0; + for (int address=0; address<256; address+=2) { + if (!i2c.write(address, NULL, 0)) { // 0 returned is ok + printf(" - I2C device found at address 0x%02X\n", address); + count++; + } + } + printf("%d devices found\n", count); +}
diff -r 000000000000 -r 4f78cdfc99de mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Sep 03 21:51:26 2009 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/f63353af7be8