Jonathan Goret
/
i2c_scan
i2c scan peripheriques
Diff: main.cpp
- Revision:
- 0:b4f549ac73a6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Mar 31 14:28:20 2015 +0000 @@ -0,0 +1,21 @@ +#include "mbed.h" + +I2C i2c(PB_9, PB_8); +Serial debug(SERIAL_TX, SERIAL_RX); + +char data [255]; +int i; +int main() + +{ + debug.format(8,Serial::None,1); +debug.baud(115200); + debug.printf("started.. \n"); + // Scan for I2C devices that reply with ack + for (i=0; i<=254; i=i+2) { + if (i2c.read(i, &data[0], 1) ==0) + { + debug.printf("I2C device detected at address=%2.2X\n\r", i); + } + } +} \ No newline at end of file