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.
Diff: main.cpp
- Revision:
- 0:96fa55991f93
- Child:
- 1:ac7a077c0039
diff -r 000000000000 -r 96fa55991f93 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Apr 25 05:48:21 2022 +0000
@@ -0,0 +1,41 @@
+#include "mbed.h"
+
+#define BUFFER_SIZE 8
+#define SLAVE_ADDR 0xA0
+
+Serial pc(USBTX, USBRX);
+I2C master(I2C_SDA, I2C_SCL);
+
+static const char* to_send[] = { "abcde", "12345", "EFGHI" };
+int main()
+{
+ pc.printf("\x1b[2J"); //CLEAR
+ pc.printf("\r"); //Mueve cursor al origen
+ pc.printf("MASTER\r\n");
+
+ master.frequency (100000);
+ char buf[BUFFER_SIZE];
+ int send_index = 0;
+ while (1)
+ {
+ strcpy(buf, to_send[send_index]);
+
+ // Write the new message to the slave
+ if (master.write(SLAVE_ADDR, buf, BUFFER_SIZE) == 0)
+ {
+ pc.printf("Written to slave: %s\r\n", buf);
+ }
+ // Read what the slave has (should be identical)
+
+ if (master.read(SLAVE_ADDR, buf, BUFFER_SIZE) == 0) {
+ pc.printf("Read from slave: %s\r\n", buf);
+ }
+
+ // Change the message we're writing to the slave
+ send_index++;
+ if (send_index > 2) {
+ send_index = 0;
+ }
+
+ }
+}