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.

This commit is contained in:
jantje 2015-07-02 21:51:51 +02:00 committed by Martino Facchin
parent fb7c2cc02e
commit 11472bf771
1 changed files with 19 additions and 1 deletions

View File

@ -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)