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: I2CSlaveComm.cpp
- Revision:
- 1:85afd4bd4651
- Parent:
- 0:265fff2cfb0a
- Child:
- 2:d0308b3aaf69
diff -r 265fff2cfb0a -r 85afd4bd4651 I2CSlaveComm.cpp
--- a/I2CSlaveComm.cpp Tue Oct 30 15:52:54 2018 +0000
+++ b/I2CSlaveComm.cpp Wed Oct 31 14:52:28 2018 +0000
@@ -79,42 +79,53 @@
switch (rx)
{
case I2CSlave::ReadAddressed:
- printf("%02x\n", RAMBuffer[PointOnAddress]);
- slave.write(&RAMBuffer[PointOnAddress], 0xF0 - PointOnAddress);
- printf("ReadAddressed 1\n");
+ slave.write(&RAMBuffer[PointOnAddress], 0xFF - PointOnAddress);
break;
/*case I2CSlave::WriteGeneral:
break;*/
case I2CSlave::WriteAddressed:
- slave.read(buf, MAX_WRITE_SIZE + 1);
+ int ret = slave.read(buf, 1);
PointOnAddress = buf[0];
nbRx = slave.getCount();
- //PcUart.printf("nb rx %d\r\n", nbRx);
- if (nbRx > 0)
- SaveRamBuffer(PointOnAddress, &buf[1], nbRx);
- printf("WriteAddressed 1\n");
+ if (nbRx > 0) //to simulate write on EEPROM need to test
+ {
+ ret = slave.read(buf, nbRx);
+ SaveRamBuffer(PointOnAddress, buf, nbRx);
+ }
+ printf("nb rx %d %d\r\n", nbRx, PointOnAddress);
+
break;
}
+ wait_ms(1);
}
void I2C_2Process()
{
+ char buf[MAX_WRITE_SIZE + 1];
int rx = slave2.receive();
+ int nbRx = 0;
switch (rx)
{
case I2CSlave::ReadAddressed:
slave2.write((char*)&ReadADCValue, 2);
- printf("ReadAddressed 2 end\n");
+ printf("ReadAddressed 2 end\n");
break;
/*case I2CSlave::WriteGeneral:
break;*/
- /*case I2CSlave::WriteAddressed:
- //do nothing
- break;*/
+ case I2CSlave::WriteAddressed:
+ //to empty read buffer we do nothing with the data
+ int ret = slave2.read(buf, 1);
+ nbRx = slave.getCount();
+ if (nbRx > 0) //to simulate write on EEPROM need to test
+ {
+ ret = slave2.read(buf, nbRx);
+ }
+ printf("nb rx2 %d %d\r\n", nbRx, PointOnAddress);
+ break;
}
}
@@ -140,6 +151,5 @@
stSensor.crc = ComputeCRC8(((char *)&stSensor)+1, sizeof(SmartSensorStruct_packed) - 7, 0);
SaveRamBuffer(0, (char*)&stSensor, sizeof(SmartSensorStruct_packed));
-
slave2.address(0x90);
}
\ No newline at end of file