From 11472bf7712586bf341e61a2f6b7990caed302a0 Mon Sep 17 00:00:00 2001 From: jantje Date: Thu, 2 Jul 2015 21:51:51 +0200 Subject: [PATCH] proposal for arduino/Ardiono#3290 I only did the change for the master begins to avoid flipflopping if more than 1 Arduino is used on a I2C. --- libraries/Wire/src/Wire.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/libraries/Wire/src/Wire.cpp b/libraries/Wire/src/Wire.cpp index d2146f7..6c0051c 100644 --- a/libraries/Wire/src/Wire.cpp +++ b/libraries/Wire/src/Wire.cpp @@ -53,6 +53,18 @@ TwoWire::TwoWire() void TwoWire::begin(void) { +/*make sure all slaves can finish their messages started before a reset*/ + pinMode(SCL, OUTPUT); + for (int i = 0; i < 8; i++) + { + digitalWrite(SCL, HIGH); + delayMicroseconds(3); + digitalWrite(SCL, LOW); + delayMicroseconds(3); + } + pinMode(SCL, INPUT); +/*End of: make sure all slaves can finish their messages started before a reset*/ + rxBufferIndex = 0; rxBufferLength = 0; @@ -67,7 +79,13 @@ void TwoWire::begin(uint8_t address) twi_setAddress(address); twi_attachSlaveTxEvent(onRequestService); twi_attachSlaveRxEvent(onReceiveService); - begin(); + rxBufferIndex = 0; + rxBufferLength = 0; + + txBufferIndex = 0; + txBufferLength = 0; + + twi_init(); } void TwoWire::begin(int address)