@@ -47,6 +47,8 @@ namespace mbed {
4747 *
4848 * #if BUILD_I2C_SLAVE
4949 *
50+ * // Slave side of the example
51+ *
5052 * #if !DEVICE_I2CSLAVE
5153 * #error [NOT_SUPPORTED] I2C Slave is not supported
5254 * #endif
@@ -55,68 +57,68 @@ namespace mbed {
5557 *
5658 * int main() {
5759 *
58- * char buf[BUFFER_SIZE] = "ABCDE";
59- *
60- * slave.address(SLAVE_ADDR);
61- * while (1) {
62- * int i = slave.receive();
63- * switch (i) {
64- * case I2CSlave::ReadAddressed:
65- * // Write back the buffer from the master
66- * slave.write(buf, BUFFER_SIZE);
67- * printf("Written to master (addressed): %s\n", buf);
68- * break;
69- * case I2CSlave::WriteGeneral:
70- * slave.read(buf, BUFFER_SIZE);
71- * printf("Read from master (general): %s\n", buf);
72- * break;
73- * case I2CSlave::WriteAddressed:
74- * slave.read(buf, BUFFER_SIZE);
75- * printf("Read from master (addressed): %s\n", buf);
76- * break;
77- * }
78- * }
60+ * char buf[BUFFER_SIZE] = "ABCDE";
61+ *
62+ * slave.address(SLAVE_ADDR);
63+ * while (1) {
64+ * int i = slave.receive();
65+ * switch (i) {
66+ * case I2CSlave::ReadAddressed:
67+ * // Write back the buffer from the master
68+ * slave.write(buf, BUFFER_SIZE);
69+ * printf("Written to master (addressed): %s\n", buf);
70+ * break;
71+ *
72+ * case I2CSlave::WriteGeneral:
73+ * slave.read(buf, BUFFER_SIZE);
74+ * printf("Read from master (general): %s\n", buf);
75+ * break;
76+ *
77+ * case I2CSlave::WriteAddressed:
78+ * slave.read(buf, BUFFER_SIZE);
79+ * printf("Read from master (addressed): %s\n", buf);
80+ * break;
81+ * }
82+ * }
7983 * }
8084 *
8185 * #else
8286 *
83- *
87+ * // Master side of the example
8488 *
8589 * I2C master(p3, p4);
8690 *
8791 * static const char* to_send[] = { "abcde", "12345", "EFGHI" };
8892 *
8993 * int main() {
90- *
91- * char buf[BUFFER_SIZE];
92- * int send_index = 0;
93-
94- * while (1) {
95- * strcpy(buf, to_send[send_index]);
96- *
97- * // Write the new message to the buffer
98- * if (master.write(SLAVE_ADDR, buf, BUFFER_SIZE)) {
99- * printf("Failed to write to slave!\n");
100- * } else {
101- * printf("Written to slave: %s\n", buf);
102- * }
103- *
104- * // Read what the slave has (should be identical)
105- * if (master.read(SLAVE_ADDR, buf, BUFFER_SIZE)) {
106- * printf("Failed to read from slave!\n");
107- * } else {
108- * printf("Read from slave: %s\n", buf);
109- * }
110- *
111- * // Change the message we're writing to the slave
112- * send_index++;
113- * if (send_index > 2) {
114- * send_index = 0;
115- * }
116- *
117- * wait_us(500000); // Wait 0.5s
118- *
119- * }
94+ * char buf[BUFFER_SIZE];
95+ * int send_index = 0;
96+ *
97+ * while (1) {
98+ * strcpy(buf, to_send[send_index]);
99+ *
100+ * // Write the new message to the slave
101+ * if (master.write(SLAVE_ADDR, buf, BUFFER_SIZE)) {
102+ * printf("Failed to write to slave!\n");
103+ * } else {
104+ * printf("Written to slave: %s\n", buf);
105+ * }
106+ *
107+ * // Read what the slave has (should be identical)
108+ * if (master.read(SLAVE_ADDR, buf, BUFFER_SIZE)) {
109+ * printf("Failed to read from slave!\n");
110+ * } else {
111+ * printf("Read from slave: %s\n", buf);
112+ * }
113+ *
114+ * // Change the message we're writing to the slave
115+ * send_index++;
116+ * if (send_index > 2) {
117+ * send_index = 0;
118+ * }
119+ *
120+ * wait_us(500000); // Wait 0.5s
121+ * }
120122 * }
121123 *
122124 * #endif
0 commit comments