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.
Revision 0:eac9f05ba8e0, committed 2018-07-07
- Comitter:
- amateusz
- Date:
- Sat Jul 07 13:18:17 2018 +0000
- Commit message:
- Ultimate I2C scanner. An Arduino port
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed-os.lib | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r eac9f05ba8e0 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sat Jul 07 13:18:17 2018 +0000
@@ -0,0 +1,34 @@
+#include "mbed.h"
+
+Serial pc(USBTX, USBRX, 115200);
+
+
+I2C i2c(PC_1, PC_0); // SDA, SCL L476 all on the left side
+//I2C i2c(PB_9, PB_8); // SDA, SCL arduino pins
+//I2C i2c(PB_14, PB_13); // SDA, SCL
+DigitalOut led(D13);
+
+int main()
+{
+ i2c.frequency(100000);
+ while (1) {
+ pc.printf("Searching for I2C devices...\n\r");
+
+ int count = 0;
+ for (int address = 0; address < 255; address +=2) { // check only for device's read addres
+ if (!i2c.write(address, NULL, 0)) { // 0 returned is ok
+ pc.printf("I2C device found at address 0x%02X (0x%02X in 8-bit)\n\r", address >> 1, address); // the address is without LSB, which is R/W flag. shoft it right once
+ count++;
+ led = 1;
+ }
+ wait(0.02);
+ }
+ if (count)
+ pc.printf("%d", count);
+ else
+ pc.printf("No");
+ pc.printf(" device%c found\n\r\n", count == 1?'\0':'s');
+ led = 0;
+ wait (1.8);
+ }
+}
\ No newline at end of file
diff -r 000000000000 -r eac9f05ba8e0 mbed-os.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Sat Jul 07 13:18:17 2018 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#35fa909641fedcad9bbe0c7300d4ccdf15a2b71a