-
-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix bug #1354: I2C/TWI Library: Buffer Overflow #1363
base: master
Are you sure you want to change the base?
Conversation
I'm not sure if this is the proper fix for this issue, it might have side effects or leave different aspects of this issue unfixed. Now that I know this patch fixes the issue, I'm sure I've identified the cause of the issue and I'll have a closer look next week. |
matthijs, do you have a proper fix for this issue? |
I have been distracted by some fixes in the HardwareSerial driver, so I haven't actually worked on this one yet. It's still on my todolist, though, so I'll get back to you (probably not until next week though). |
Any news about this issue? |
I've encountered this bug as well and would love to see this merged. |
@cmaglie this looks good to merge to me. It will resolve https://github.com/arduino/Arduino/issues/486 as well. I've tested with a Uno to Uno Wire setup by artificially lowering the slave RX buffer size:
and the following sketches: Master (modified version of #include <Wire.h>
void setup() {
Serial.begin(9600);
Wire.begin(); // join i2c bus (address optional for master)
}
void loop() {
Wire.beginTransmission(8); // transmit to device #8
Wire.write("fedcba9876543210");
Serial.println(Wire.endTransmission(), HEX); // stop transmitting
delay(500);
Wire.beginTransmission(8); // transmit to device #8
Wire.write("0123456789");
Serial.println(Wire.endTransmission(), HEX);
delay(500);
} Slave (modified version of #include <Wire.h>
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop() {
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
Serial.println(howMany);
while (Wire.available()) {
char c = Wire.read();
Serial.print(c);
}
Serial.println();
} Output of master sketch alternates between 0 and 3 (success and data send, NACK received). |
If we send i2c data larger than the arduino buffer (default: 32bytes) the arduino waits infinitely in a while loop (freeze). This fixes this.