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
Fork of minimal_i2c_mother by
Diff: master.cpp
- Revision:
- 0:d3bdf717512e
- Child:
- 1:92677fbab5f1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/master.cpp Thu Nov 20 16:13:26 2014 +0000
@@ -0,0 +1,42 @@
+#include "mbed.h"
+
+I2C Bus(p28, p27);
+int slaveAddress;
+
+Serial Usb(USBTX, USBRX);
+char buffer[16] = {'T', 'e', 's', 't', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+int ack;
+
+DigitalOut sent(LED1);
+DigitalOut received(LED2);
+
+void resetBus()
+{
+ Bus.stop();
+ Bus.start();
+ return;
+}
+
+int main()
+{
+ slaveAddress = 0x02;
+ resetBus();
+
+ while (1)
+ {
+ for(int i = 0; i < sizeof buffer; buffer[i++]=0x00);
+ Usb.scanf("%s", buffer);
+ Usb.printf("%s \n\r", buffer);
+
+ ack = Bus.write(slaveAddress & 0xFE, buffer, 16);
+ if(ack == 0)
+ Usb.printf(" ...Ack \n\r");
+
+ ack = Bus.write(0, buffer, 16);
+ if(ack == 0)
+ Usb.printf("Ack from broadcast \n\r");
+
+ Bus.read(slaveAddress | 1, buffer, 16, 0);
+ Usb.printf("Received: %s \n\r", buffer);
+ }
+}
\ No newline at end of file
