Arduino Due + Yun multi-master I2C strange behaviour.

Hello forum! I’m doing some project, which requires multi-master i2c design.
This is sketch and problem explained:

master_writer (look carefully, I’m setting address of master to 5).

// Wire Master Writer
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Writes data to an I2C/TWI slave device
// Refer to the "Wire Slave Receiver" example for use with this

// Created 29 March 2006

// This example code is in the public domain.


#include <Wire.h>

void setup()
{
  Wire.begin(5); // join i2c bus (address optional for master)
  Serial.begin(9600);
}

byte x = 0;

void loop()
{
  Wire.beginTransmission(4); // transmit to device #4
  Wire.write("x is ");        // sends five bytes
  Wire.write(x);              // sends one byte
  byte res = Wire.endTransmission();    // stop transmitting
  
  Serial.print("Wire.endTransmission() returned ");
  Serial.println(res);

  x++;
  delay(500);
}

slave_receiver

// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this

// Created 29 March 2006

// This example code is in the public domain.


#include <Wire.h>

void setup()
{
  Wire.begin(4);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
}

void loop()
{
  delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
  while(1 < Wire.available()) // loop through all but the last
  {
    char c = Wire.read(); // receive byte as a character
    Serial.print(c);         // print the character
  }
  int x = Wire.read();    // receive byte as an integer
  Serial.println(x);         // print the integer
}

master_writer on Yun and slave_receiver on Due works fine. output is:

Wire.endTransmission() returned 0
Wire.endTransmission() returned 0
Wire.endTransmission() returned 0
...

but slave_receiver on Yun and master_writer on Due returns this:

Wire.endTransmission() returned 2
Wire.endTransmission() returned 2
Wire.endTransmission() returned 2
...

which means “received NACK on transmit of address”
also, I tested same thing on Yun and Mega, it worked fine.
any thoughts?

Regards.

EDIT: I also tried master_writer on Due (original one, without setting an address) and slave_receiver on Yun and it worked fine.

If you give Wire.begin() an address then it only acts as a slave; it can never be a master.

This is a deficiency in the library, not the underlying hardware.

But exactly same thing works fine when I'm testing Yun + Mega boards.

Regards.

seems this guy fixed it while ago (same problem), but when I checked source, it's quite modified and can't modify/replace due compiling errors. http://forum.arduino.cc/index.php?topic=267447.0

any ideas?

Regards.