Skip to content

Commit 11472bf

Browse files
jantjefacchinm
authored andcommitted
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.
1 parent fb7c2cc commit 11472bf

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

libraries/Wire/src/Wire.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ TwoWire::TwoWire()
5353

5454
void TwoWire::begin(void)
5555
{
56+
/*make sure all slaves can finish their messages started before a reset*/
57+
pinMode(SCL, OUTPUT);
58+
for (int i = 0; i < 8; i++)
59+
{
60+
digitalWrite(SCL, HIGH);
61+
delayMicroseconds(3);
62+
digitalWrite(SCL, LOW);
63+
delayMicroseconds(3);
64+
}
65+
pinMode(SCL, INPUT);
66+
/*End of: make sure all slaves can finish their messages started before a reset*/
67+
5668
rxBufferIndex = 0;
5769
rxBufferLength = 0;
5870

@@ -67,7 +79,13 @@ void TwoWire::begin(uint8_t address)
6779
twi_setAddress(address);
6880
twi_attachSlaveTxEvent(onRequestService);
6981
twi_attachSlaveRxEvent(onReceiveService);
70-
begin();
82+
rxBufferIndex = 0;
83+
rxBufferLength = 0;
84+
85+
txBufferIndex = 0;
86+
txBufferLength = 0;
87+
88+
twi_init();
7189
}
7290

7391
void TwoWire::begin(int address)

0 commit comments

Comments
 (0)