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:
- 1:92677fbab5f1
- Parent:
- 0:d3bdf717512e
- Child:
- 2:4709985cf716
--- a/master.cpp Thu Nov 20 16:13:26 2014 +0000
+++ b/master.cpp Tue Dec 02 17:41:35 2014 +0000
@@ -1,12 +1,21 @@
#include "mbed.h"
+#define ROWSIZE (3)
+#define SELECTSIZE (0x04)
+//BusOut toCells(p5,p6,p7,p8,p9,p10,p11,p12);
+//BusOut select(p13,p14,p15);
+
I2C Bus(p28, p27);
-int slaveAddress;
+//I2CSlave Self(p9, p10);
+
+int slaveAddressRow1;
+int slaveAddressRow2;
Serial Usb(USBTX, USBRX);
-char buffer[16] = {'T', 'e', 's', 't', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+char buffer[16] = {0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x00};
int ack;
+char slaveBuffer[16];
DigitalOut sent(LED1);
DigitalOut received(LED2);
@@ -19,24 +28,54 @@
int main()
{
- slaveAddress = 0x02;
+ slaveAddressRow1 = 0x02;
+ //slaveAddressRow2 = 0x04;
+ //Self.address(slaveAddressRow2);
resetBus();
while (1)
{
- for(int i = 0; i < sizeof buffer; buffer[i++]=0x00);
- Usb.scanf("%s", buffer);
- Usb.printf("%s \n\r", buffer);
+ //for(int i = 0; i < sizeof buffer; buffer[i++]=0x00);
+ //Usb.scanf("%s", buffer);
+ //Usb.printf("%s \n\r", buffer);
+
+ wait(1);
+
+ int ack1 = Bus.write(slaveAddressRow1 & 0xFE, buffer, 16);
+ if(ack1 == 0)
+ Usb.printf("Row one sent\n\r");
+ else
+ Usb.printf("No Ack");
+ //ack2 = Bus.write(slaveAddressRow2 & 0xFE, buffer, 16);
+ //if(ack2 == 0)
+ // Usb.printf("Row two sent\n\r");
- 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");
+ /*int i = Bus.receive();
+ switch (i)
+ {
+ case I2CSlave::ReadAddressed:
+ Bus.write(slaveBuffer, 16);
+ PC.printf("wrote: %s \n\r", buffer);
+ break;
+ case I2CSlave::WriteGeneral:
+ Bus.read(slaveBuffer, 16);
+ PC.printf("received broadcast: %s \n\r", buffer);
+ break;
+ case I2CSlave::WriteAddressed:
+ Bus.read(slaveBuffer, 16);
+ PC.printf("received message: %s \n\r", buffer);
+ break;
+ }
- Bus.read(slaveAddress | 1, buffer, 16, 0);
- Usb.printf("Received: %s \n\r", buffer);
+ char cell = SELECTSIZE;
+ for(j = 0; j < ROWSIZE; j++)
+ {
+ toCells = buffer[j];
+ select = cell;
+ cell >>= 1;
+ wait(0.1);
+ select = 0x00;
+ }
+ */
}
}
\ No newline at end of file
