Skip to content

Corrected TwoWire::onRequestService(void) to correctly reset the write buffer before send frame. #22

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

Merged
merged 2 commits into from
Mar 8, 2019

Conversation

goodchip
Copy link
Contributor

Hi!

txBufferIndex and txBufferLength is used in TwoWire::write(uint8_t data) of the original ATMEGA328p Wire library for control the iteration of write buffer...

...but no longer control the buffer since TwoWire::write(uint8_t data) is modified for run with megaavr architecture (the new variable for control it is slave_bytesToWrite).

I've modified TwoWire::onRequestService(void) for reset correctly the buffer before than the slave send his datas.


This sample code slave side shows the problem: (in using the ATMEGA4809 chip from Arduino Uno WiFi Rev2)

#include <Wire.h>

void setup() {
  Wire.begin(0x10);
  Wire.onRequest(reqIRQ);
}

void loop() {
  delay(1000);
}

void reqIRQ() {
  Wire.write(0x01);
  Wire.write(0x02);
  Wire.write(0x03);
}

1st read on master at 0x10 address:

0x01
0x02
0x03

2nd read on master at 0x10 address:

0x01
0x02
0x03
0x01
0x02
0x03

3th read on master at 0x10 address:

0x01
0x02
0x03
0x01
0x02
0x03
0x01
0x02
0x03

etc.

Corrected TwoWire::onRequestService(void) to correctly reset the write buffer before send frame.
txBufferIndex and txBufferLength no longer control the buffer since TwoWire::write(uint8_t data) is modified for run with megaavr architecture.
@facchinm
Copy link
Member

LGTM! Merging

@goodchip
Copy link
Contributor Author

goodchip commented Mar 7, 2019

Hello @facchinm, peer validation before merge maybe?

@facchinm facchinm merged commit 0b4b24f into arduino:master Mar 8, 2019
@facchinm
Copy link
Member

facchinm commented Mar 8, 2019

Sorry for the delay, I was almost sure I pressed the button 😭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants