You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have run into a problem with the Wire library and tracked it down to commit 48ff3a10ad465afc08a76874cf0e9ef25a6da86a and i believe the changes done in that commit is actually wrong.
If you have an arduino program that uses the Wire library as a i2c slave and it takes advantage of clock stretching in the onReceive event handler then it will lose data if the master sends data too fast.
The next command that was sent will most of the time only have 1 byte received instead of several.
Reverting commit 48ff3a10ad465afc08a76874cf0e9ef25a6da86a fixes the problem.
I have attached a sample program that i used to test the problem.
This program simulates the slave taking a long time by using a 1 second delay in the onReceive event handler.
To reproduce the problem, use attached file (i'm using a 328p) and then from the attached linux computer send several i2c write commands in quick succession.
for example: i2cset -y 3 0x04 0x01 0x02 0x03 0x04 i;i2cset -y 3 0x04 0x01 0x02 0x03 0x04 i;i2cset -y 3 0x04 0x01 0x02 0x03 0x04 i;i2cset -y 3 0x04 0x01 0x02 0x03 0x04 i;
first command will work and serial port on arduino will print the sent data.
second command and all following will only print first byte.
after reverting above commit output is as expected and no data loss.
Note that i'm not testing this with a raspberry pi since i read it have a bug in its i2c implementation affecting clock stretching.
Also this is related to issue arduino/Arduino#1477
From a quick look at the code and the problematic commit (which is 48bcef5 in this repository), that commit indeed looks wrong to me (I expect it will break clock stretching by an Arduino I2c slave. It is intended to fix arduino/Arduino#1477, but from that report I cannot quite figure out what the actual problem is, so I suspect this commit does not actually fix that problem, just works around it somehow. Maybe the Arduino I2c master fails to support clock stretching properly?
Hello.
I have run into a problem with the Wire library and tracked it down to commit 48ff3a10ad465afc08a76874cf0e9ef25a6da86a and i believe the changes done in that commit is actually wrong.
If you have an arduino program that uses the Wire library as a i2c slave and it takes advantage of clock stretching in the onReceive event handler then it will lose data if the master sends data too fast.
The next command that was sent will most of the time only have 1 byte received instead of several.
Reverting commit 48ff3a10ad465afc08a76874cf0e9ef25a6da86a fixes the problem.
I have attached a sample program that i used to test the problem.
This program simulates the slave taking a long time by using a 1 second delay in the onReceive event handler.
To reproduce the problem, use attached file (i'm using a 328p) and then from the attached linux computer send several i2c write commands in quick succession.
for example: i2cset -y 3 0x04 0x01 0x02 0x03 0x04 i;i2cset -y 3 0x04 0x01 0x02 0x03 0x04 i;i2cset -y 3 0x04 0x01 0x02 0x03 0x04 i;i2cset -y 3 0x04 0x01 0x02 0x03 0x04 i;
first command will work and serial port on arduino will print the sent data.
second command and all following will only print first byte.
after reverting above commit output is as expected and no data loss.
WireStretchTest.txt
The text was updated successfully, but these errors were encountered: