arduino / arduino/ArduinoCore-avr
Please revert commit 48ff3a10ad465afc08a76874cf0e9ef25a6da86a
- Dominant language
- C
- Stars
- 1.5k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
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](https://github.com/arduino/Arduino/files/429000/WireStretchTest.txt)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reviewing commit 48ff3a10ad465afc08a76874cf0e9ef25a6da86a and the WireStretchTest.txt reproduction attached to the issue. Run the Arduino slave on an ATmega328P and send repeated i2cset commands from Linux, then compare behavior with and without the commit. Done means the Wire library receives all bytes from successive writes while the onReceive handler uses clock stretching.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100