![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
i2c scan peripheriques
main.cpp@0:b4f549ac73a6, 2015-03-31 (annotated)
- Committer:
- johnylafleur
- Date:
- Tue Mar 31 14:28:20 2015 +0000
- Revision:
- 0:b4f549ac73a6
i2c scan peripheriques
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
johnylafleur | 0:b4f549ac73a6 | 1 | #include "mbed.h" |
johnylafleur | 0:b4f549ac73a6 | 2 | |
johnylafleur | 0:b4f549ac73a6 | 3 | I2C i2c(PB_9, PB_8); |
johnylafleur | 0:b4f549ac73a6 | 4 | Serial debug(SERIAL_TX, SERIAL_RX); |
johnylafleur | 0:b4f549ac73a6 | 5 | |
johnylafleur | 0:b4f549ac73a6 | 6 | char data [255]; |
johnylafleur | 0:b4f549ac73a6 | 7 | int i; |
johnylafleur | 0:b4f549ac73a6 | 8 | int main() |
johnylafleur | 0:b4f549ac73a6 | 9 | |
johnylafleur | 0:b4f549ac73a6 | 10 | { |
johnylafleur | 0:b4f549ac73a6 | 11 | debug.format(8,Serial::None,1); |
johnylafleur | 0:b4f549ac73a6 | 12 | debug.baud(115200); |
johnylafleur | 0:b4f549ac73a6 | 13 | debug.printf("started.. \n"); |
johnylafleur | 0:b4f549ac73a6 | 14 | // Scan for I2C devices that reply with ack |
johnylafleur | 0:b4f549ac73a6 | 15 | for (i=0; i<=254; i=i+2) { |
johnylafleur | 0:b4f549ac73a6 | 16 | if (i2c.read(i, &data[0], 1) ==0) |
johnylafleur | 0:b4f549ac73a6 | 17 | { |
johnylafleur | 0:b4f549ac73a6 | 18 | debug.printf("I2C device detected at address=%2.2X\n\r", i); |
johnylafleur | 0:b4f549ac73a6 | 19 | } |
johnylafleur | 0:b4f549ac73a6 | 20 | } |
johnylafleur | 0:b4f549ac73a6 | 21 | } |