Closed MkLHX closed 2 years ago
Hi @MkLHX . Starting at version 0.3.0, you must send an empty packet to trigger the onRequest callback. So it's just 4 bytes: [start = 0x02][length = 0x04][crc = 0x61][end = 0x04]
. Check the triggerUpdate()
method:
By the way, I think your CRC may be incorrect. From your example, your payload is 0xF4 = 244
, so the CRC input is [0x05 0xF4]
. Putting this on an online CRC8 calculator yields 0xEA = 234
(MAXIM algorithm), not 21 as it's on your debug output.
@gutierrezps is CRC8 calculation correct Maxim CRC8? I'm trying to communicate with raspberry but CRC seems way off to me and therefore i2c will not send responses as it discards packets that it thinks have wrong CRC.
WirePacker packer;
packer.write(1);
packer.end();
packer.printToSerial();
Output: length: 5, closed, buffer str: '...^.', buffer hex: 02 05 01 5E 04
https://crccalc.com/ gives me different results
WirePacker packer2;
packer2.end();
packer2.printToSerial();
Output: length: 4, closed, buffer str: '....', buffer hex: 02 04 00 04
I am using master branch. so 0.3.0
@gutierrezps I think another problem is that seed
in never updated/set to new value at the end of method and therefore CRC is always calculated for last update call data and previous call CRC are disregarded
uint8_t update(uint8_t *data, unsigned int length) {
uint8_t crc = seed;
uint8_t extract;
uint8_t sum;
for (unsigned int i = 0; i < length; i++) {
extract = *data;
for (char j = 8; j; j--) {
sum = (crc ^ extract) & 0x01;
crc >>= 1;
if (sum) {
crc ^= 0x8C;
}
extract >>= 1;
}
data++;
}
seed = crc; // should be something like that
return crc;
}
Unfortunately, I couldn't address this issue in a timely manner because I haven't been working with the ESP32 ever since. In this meantime, I2C Slave support has been added to the official ESP32 framework as you can see in the updated README of this repo. Therefore this library is no longer needed and its development will be ceased.
TL;DR go to the end of issue
Hello,
Back on my project with raspberry pi as master and esp32 as slave.
In the last months everythings works well and was so great. I doing a break from this part of the project.
Today i back on it and i'm facing a strange behavior with the method WireSlave.onRequest(requestEvent);
When i send i2c request from master with the good data format the WireSlave.onReceive(receiveEvent); get the data but the
WireSlave.onRequest(requestEvent); never run and send nothing to the master....
This is my test sketch on esp32 side directly copied from this repo:
this is my raspberry pi side python code (including python classes from https://github.com/MkLHX/Raspberry_Pi_Master_for_ESP32_I2C_SLAVE for more readable i remove Packer, Unpacker and Crc8 classes from snippet:
the anwser on esp32 is:
the answer on raspberry pi:
We can see the device is found 0x60 = 96 the data to pack as waiting esp32 slave is 244 and formated bytearray is good with first, length, data, crc8, last parameters.
But the ESP32 doesn't return anything to the rpi so the unpacked instance crash.
So my question is why WireSlave.onRequest(requestEvent); seems to do nothing when i2c event is triggered? And how to debug it ASAP? because my project need to be deliver next week and now nothing works.
Don't change anything juste take the code i wrote few months ago and re run it.
I see i used the latest release 0.0.3 seems to fix update blocking but maybe not (in my case)
how can i rollback to the v0.2.0 to test it?
EDIT: i download the archive of v0.2.0, put it in lib/ folder on pio project and my project rollback to works! i think there is a bug between python raspberry and v0.3.0...