Michael Baker
/
I2C_Bus_Scanner
Program to scan I2C bus for device addresses
Revision 0:545d57fc4eca, committed 2017-01-26
- Comitter:
- michaelVisimid
- Date:
- Thu Jan 26 19:28:55 2017 +0000
- Commit message:
- Initial commit
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 Thu Jan 26 19:28:55 2017 +0000 @@ -0,0 +1,30 @@ +// Original program found here: http://playground.arduino.cc/Main/I2cScanner +// Modified by Domen Ornik, 4.5.2015 + +#include "mbed.h" + +I2C i2c(I2C_SDA , I2C_SCL ); + +int returnCode, address, numberOfDevices = 0; +char outByte = 0xAA; + +int main() { + printf("\r\nI2C Bus Scanner\r\n"); + numberOfDevices = 0; + for(address = 1; address < 127; address++ ){ + returnCode = i2c.write((address << 1),&outByte,1,0); + if (returnCode == 0) + { + printf("I2C device found at address 0x%X\r\n", address); + numberOfDevices++; + } + + } + if (numberOfDevices == 0){ + printf("No I2C devices found\r\n"); + } + else{ + printf("Number of devices: %d\r\n",numberOfDevices); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Jan 26 19:28:55 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/ad3be0349dc5 \ No newline at end of file