opp
Dependencies: mbed
Fork of LAB11_Oppgave01 by
main.cpp@1:2d9d32fc4f5d, 2015-11-10 (annotated)
- Committer:
- rlanghbv
- Date:
- Tue Nov 10 13:25:36 2015 +0000
- Revision:
- 1:2d9d32fc4f5d
- Parent:
- 0:81fa0e3e8a6c
- Child:
- 2:3d70a9ba2a58
First commit
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() |
rlanghbv | 0:81fa0e3e8a6c | 6 | { |
rlanghbv | 1:2d9d32fc4f5d | 7 | i2cBus.frequency(100000); |
rlanghbv | 1:2d9d32fc4f5d | 8 | |
rlanghbv | 1:2d9d32fc4f5d | 9 | int i2cAddres=0x68; // Address of DS1307 is 0x68 (7 bit address) |
rlanghbv | 1:2d9d32fc4f5d | 10 | int i2c8BitAddres= i2cAddres <<1; // Convert to 8bit addressing used by mbed |
rlanghbv | 1:2d9d32fc4f5d | 11 | |
rlanghbv | 1:2d9d32fc4f5d | 12 | int result=i2cBus.write(i2c8BitAddres, NULL, 0); |
rlanghbv | 1:2d9d32fc4f5d | 13 | |
rlanghbv | 1:2d9d32fc4f5d | 14 | //0 on success (ack), non-0 on failure (nack) |
rlanghbv | 1:2d9d32fc4f5d | 15 | if (result==0) |
rlanghbv | 1:2d9d32fc4f5d | 16 | printf("I2C device found at address 0x%02X \r\n", i2cAddres); |
rlanghbv | 1:2d9d32fc4f5d | 17 | else |
rlanghbv | 1:2d9d32fc4f5d | 18 | printf("I2C device Not found at address 0x%02X \r\n", i2cAddres); |
rlanghbv | 0:81fa0e3e8a6c | 19 | } |
rlanghbv | 0:81fa0e3e8a6c | 20 |