Creating a custom “communication protocol” between 2 particle devices via I2C, one acting as a slave(photon) and one as a master(argon), I was lead many times reading invalid values (value 0x31). Specifically, when I try to read from the master, and the slave lags behind I usually get this value (which is not present in the data that I send, but its not random as well). In conclussion I read invalid bytes when it seems that master can read, but actually the slave doesn’t send anything or writes slowly. Does anybody observed something similar?
Update: I did some more digging around. The slave address I was using is 0x18, which, as I understand, is shifted to the left (x2) and the last bit is (0 for write 1 for read). Thus when I try to read from the slave I send the 0x18 << 2 | 1 = 0x31. Tried with different address (0x19) and I read 0x33. So now it seams that the master reads back the read command from the I2C Bus instead of reading the data sent by the slave.
Argon as the I2C master, photon I2C slave , both devices have v1.1.0 firmware. This is not the actual code, but it seems to recreate the issue. The first call of the cloud function, would result in a valid output (“456789”) and the subsequent ones would be shifted by the address byte, thus printing (“145678”).
What I was thinking along (without actually testing or pondering long about) was that when you request six bytes but get seven then the "lingering" byte may be messing up your following transmission.
I haven't yet pulled out my devices to test it hands-on.
I mentioned (requesting 7 bytes) to emphasize on input shifting, from what is seems to be the i2c read cmd byte. The bug is reproducible using the code above (6 bytes send and read).
Now I have tested all options I could think of and it really seems to be a bug in the Gen3 device OS. When inverting the roles (Photon as master, Argon as slave) things work as expected.