user31190: I'm trying to send data both ways between an Arduino Mega 2560 slave and 2  Arduino Nano Zero (ATSAMD21G).
This example is a simplified setup and code. There will be more masters along with passive slaves on the bus (LCD, EEPROM).
Code and results (txt files)
My code is working fine with one master only and the slave active on the bus (data is sent both ways every 2s). I however notice missing transfers to the masters when more than one master is active. The 2 masters to slave transfers are working properly (once the 2 masters are on, the data is received by the slave every 2s from each master).
Is this problem due to collision? How can I handle it?

user31190: The code had several issues leading to a constant flow of wrong data (with correct data in the middle) between the master that won the bus arbitration. This made it keep the bus too long and eventually give it away to the second master at a random time, with missed transfers from the second master in between. The second master was then behaving the same and so on.
receiveEvent, on the slave side, contained a millis if condition timer that made it time out. I moved the timer to the master side before calling Wire.requestFrom. Avoid slow code in receiveEvent!
receiveEvent, on the slave side, was also confusing real data with incoming requestEvent. I added an if statement to compare the receiveEvent data size with the expected size. Half of the data was wrong without this filter (this should ideally be handled in the Wire library)
These fixes solved the busy bus problem. I figured these out after asking question #35092
The bus speed also had to be reduced because 800 kHz was too fast for the Mega 2560 (but worked between 3 Nano).
The slave has to send the data destined to both masters to each of them because requestEvent can't tell which master is asking for data. The data is then filtered on each master to only keep the relevant information.
The data is now being transferred both ways between the 2 Nano masters and the Mega slave at the correct interval, without corrupt data. 
fixed Slave code
fixed Master 1 code
fixed Master 2 code in the same repo (I'm limited to 2 links post)

31190: <p>I'm trying to send data both ways between an Arduino Mega 2560 slave and 2  Arduino Nano Zero (ATSAMD21G).</p>

<p>This example is a simplified setup and code. There will be more masters along with passive slaves on the bus (LCD, EEPROM).</p>

<p><a href="https://github.com/kb-/Arduino-I2C-2way-anydata/tree/f78aa10354f7706d1aa32f49d3bc647600f2b4ee" rel="nofollow noreferrer">Code and results (txt files)</a></p>

<p>My code is working fine with one master only and the slave active on the bus (data is sent both ways every 2s). I however notice missing transfers to the masters when more than one master is active. The 2 masters to slave transfers are working properly (once the 2 masters are on, the data is received by the slave every 2s from each master).</p>

<p>Is this problem due to collision? How can I handle it?</p>
 31190: <p>The code had several issues leading to a constant flow of wrong data (with correct data in the middle) between the master that won the bus arbitration. This made it keep the bus too long and eventually give it away to the second master at a random time, with missed transfers from the second master in between. The second master was then behaving the same and so on.</p>

<p><code>receiveEvent</code>, on the slave side, contained a <code>millis</code> <code>if</code> condition timer that made it time out. I moved the timer to the master side before calling <code>Wire.requestFrom</code>. Avoid slow code in <code>receiveEvent</code>!</p>

<p><code>receiveEvent</code>, on the slave side, was also confusing real data with incoming <code>requestEvent</code>. I added an <code>if</code> statement to compare the <code>receiveEvent</code> data size with the expected size. Half of the data was wrong without this filter (this should ideally be handled in the <code>Wire</code> library)</p>

<p>These fixes solved the busy bus problem. I figured these out after asking question #35092</p>

<p>The bus speed also had to be reduced because 800 kHz was too fast for the Mega 2560 (but worked between 3 Nano).</p>

<p>The slave has to send the data destined to both masters to each of them because <code>requestEvent</code> can't tell which master is asking for data. The data is then filtered on each master to only keep the relevant information.</p>

<p>The data is now being transferred both ways between the 2 Nano masters and the Mega slave at the correct interval, without corrupt data. </p>

<p><a href="https://github.com/kb-/Arduino-I2C-2way-anydata/blob/ff9b47bdb17c137731882ec3b1b53c34afd91193/Slave_test_i2c_data/Slave_test_i2c_data.ino" rel="nofollow noreferrer">fixed Slave code</a></p>

<p><a href="https://github.com/kb-/Arduino-I2C-2way-anydata/blob/7e63e0aaeb7f2a60aad23f67b06f30f55774ce6e/Master_test_i2c_data/Master_test_i2c_data.ino" rel="nofollow noreferrer">fixed Master 1 code</a></p>

<p>fixed Master 2 code in the same repo (I'm limited to 2 links post)</p>
