Skip to content
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

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

Merged
merged 1 commit into from
Mar 6, 2019

Conversation

goodchip
Copy link
Contributor

@goodchip goodchip commented Mar 6, 2019

Hi!

Same pull request than in the genuine megaavr Arduino master :
arduino/ArduinoCore-megaavr#22


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.

@MCUdude
Copy link
Owner

MCUdude commented Mar 6, 2019

Great, thanks! Any reason why this haven't been merged in the main megaAVR repo?

@goodchip
Copy link
Contributor Author

goodchip commented Mar 6, 2019

@MCUdude: It's very recent, there may be a peer review before (?)

@MCUdude MCUdude merged commit 63e8b8c into MCUdude:master Mar 6, 2019
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