Simple program detecting if a DS1307 is connected
Dependencies: mbed
Import program
00001 #include "mbed.h" 00002 00003 I2C i2cBus(I2C_SDA, I2C_SCL); 00004 00005 int main() 00006 { 00007 i2cBus.frequency(100000); 00008 00009 int i2cAddres=0x68; // Address of DS1307 is 0x68 (7 bit address) 00010 int i2c8BitAddres= i2cAddres <<1; // Convert to 8bit addressing used by mbed 00011 00012 int result=i2cBus.write(i2c8BitAddres, NULL, 0); 00013 00014 //0 on success (ack), non-0 on failure (nack) 00015 if (result==0) 00016 printf("I2C device found at address 0x%02X \r\n", i2cAddres); 00017 else 00018 printf("I2C device Not found at address 0x%02X \r\n", i2cAddres); 00019 } 00020
main.cpp
- Committer:
- rlanghbv
- Date:
- 2015-11-10
- Revision:
- 1:2d9d32fc4f5d
- Parent:
- 0:81fa0e3e8a6c
File content as of revision 1:2d9d32fc4f5d:
#include "mbed.h" I2C i2cBus(I2C_SDA, I2C_SCL); int main() { i2cBus.frequency(100000); int i2cAddres=0x68; // Address of DS1307 is 0x68 (7 bit address) int i2c8BitAddres= i2cAddres <<1; // Convert to 8bit addressing used by mbed int result=i2cBus.write(i2c8BitAddres, NULL, 0); //0 on success (ack), non-0 on failure (nack) if (result==0) printf("I2C device found at address 0x%02X \r\n", i2cAddres); else printf("I2C device Not found at address 0x%02X \r\n", i2cAddres); }