user31190: I encountered a strange behavior while running 2 way transmission tests  between 2 Arduino Zero (ATSAMD21G), one master and one slave. Wrong data is being continuously transferred both ways. The expected data is also being transferred in between. I have to filter out the received data to catch it (line 41 in Master's code and 33 in slave).
I'm using the stock wire libraries (being different for the 2 boards), along with Nick Gammon's "I2C_readAnything".
Master's code
Slave's code
I think this continuous flow doesn't allow the bus to be released. It might be what's making it impossible to communicate with a second master (and maybe causing my previous problem)
I also tried my code between a Mega 2560 (slave) and a Zero (master). Fake data is, this time, only being sent one way (from the Zero to the Mega only).
Is there some specific code to add to send data properly from ATSAMD boards? Is it a bug in the SAMD Wire library?
I also had to add a 1ms delay after sending data from the Master. It wouldn't go through otherwise. Shouldn't it be handled by the ATSAMD or the Wire library?

user31190: The code had several issues.
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.
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)
I set the global variables used in events as volatile. The code is working too without this tho.
fixed Master code
fixed Slave code

31190: <p>I encountered a strange behavior while running 2 way transmission tests  between 2 Arduino Zero (ATSAMD21G), one master and one slave. Wrong data is being continuously transferred both ways. The expected data is also being transferred in between. I have to filter out the received data to catch it (line 41 in Master's code and 33 in slave).</p>

<p>I'm using the stock wire libraries (being different for the 2 boards), along with Nick Gammon's "I2C_readAnything".</p>

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

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

<p>I think this continuous flow doesn't allow the bus to be released. It might be what's making it impossible to communicate with a second master (and maybe causing my <a href="https://arduino.stackexchange.com/questions/34944/two-way-communication-on-multimaster-i2c-bus">previous problem</a>)</p>

<p>I also tried my code between a Mega 2560 (slave) and a Zero (master). Fake data is, this time, only being sent one way (from the Zero to the Mega only).</p>

<p>Is there some specific code to add to send data properly from ATSAMD boards? Is it a bug in the SAMD Wire library?</p>

<p>I also had to add a 1ms delay after sending data from the Master. It wouldn't go through otherwise. Shouldn't it be handled by the ATSAMD or the Wire library?</p>
 31190: <p>The code had several issues.</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>.</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>I set the global variables used in events as <code>volatile</code>. The code is working too without this tho.</p>

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

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