opp
Dependencies: mbed
Fork of LAB11_Oppgave01 by
main.cpp@2:3d70a9ba2a58, 2015-12-08 (annotated)
- Committer:
- knut_johan
- Date:
- Tue Dec 08 15:43:46 2015 +0000
- Revision:
- 2:3d70a9ba2a58
- Parent:
- 1:2d9d32fc4f5d
LAB11_
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rlanghbv | 0:81fa0e3e8a6c | 1 | #include "mbed.h" |
rlanghbv | 0:81fa0e3e8a6c | 2 | |
rlanghbv | 1:2d9d32fc4f5d | 3 | I2C i2cBus(I2C_SDA, I2C_SCL); |
rlanghbv | 0:81fa0e3e8a6c | 4 | |
rlanghbv | 0:81fa0e3e8a6c | 5 | int main() |
knut_johan | 2:3d70a9ba2a58 | 6 | { int i2cAddres; |
rlanghbv | 1:2d9d32fc4f5d | 7 | i2cBus.frequency(100000); |
rlanghbv | 1:2d9d32fc4f5d | 8 | |
knut_johan | 2:3d70a9ba2a58 | 9 | i2cAddres=0x68; |
knut_johan | 2:3d70a9ba2a58 | 10 | for(i2cAddres=3;i2cAddres<119;i2cAddres++) // I2C device found at address 0x52 |
knut_johan | 2:3d70a9ba2a58 | 11 | { |
knut_johan | 2:3d70a9ba2a58 | 12 | // Address of DS1307 is 0x68 (7 bit address) |
rlanghbv | 1:2d9d32fc4f5d | 13 | int i2c8BitAddres= i2cAddres <<1; // Convert to 8bit addressing used by mbed |
rlanghbv | 1:2d9d32fc4f5d | 14 | |
rlanghbv | 1:2d9d32fc4f5d | 15 | int result=i2cBus.write(i2c8BitAddres, NULL, 0); |
rlanghbv | 1:2d9d32fc4f5d | 16 | |
rlanghbv | 1:2d9d32fc4f5d | 17 | //0 on success (ack), non-0 on failure (nack) |
rlanghbv | 1:2d9d32fc4f5d | 18 | if (result==0) |
rlanghbv | 1:2d9d32fc4f5d | 19 | printf("I2C device found at address 0x%02X \r\n", i2cAddres); |
rlanghbv | 1:2d9d32fc4f5d | 20 | else |
knut_johan | 2:3d70a9ba2a58 | 21 | printf("I2C device Not found at address 0x%02X \r\n", i2cAddres); |
knut_johan | 2:3d70a9ba2a58 | 22 | } |
rlanghbv | 0:81fa0e3e8a6c | 23 | } |
rlanghbv | 0:81fa0e3e8a6c | 24 |