Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Revision 1:2d9d32fc4f5d, committed 2015-11-10
- Comitter:
- rlanghbv
- Date:
- Tue Nov 10 13:25:36 2015 +0000
- Parent:
- 0:81fa0e3e8a6c
- Commit message:
- First commit
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 81fa0e3e8a6c -r 2d9d32fc4f5d main.cpp
--- a/main.cpp Mon Nov 09 13:39:59 2015 +0000
+++ b/main.cpp Tue Nov 10 13:25:36 2015 +0000
@@ -1,17 +1,20 @@
#include "mbed.h"
- //SDA , SCL
-I2C i2cBus(PB_9, PB_8);
+I2C i2cBus(I2C_SDA, I2C_SCL);
int main()
{
- i2cBus.frequency(100000);
-
- //Scan the valid I2C addresrange: 0x3 to 0x77
- for (int i2cAddres=3; i2cAddres<=0x77; i2cAddres++) {
- if (!i2cBus.write(i2cAddres<<1, NULL, 0)) { // 0 if a device ACK'ed the message
- printf("\r\nI2C device found at address 0x%02X \r\n", i2cAddres);
- }
- }
+ 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);
}