Working Multi Master I2C bus

I just want to share some information about our Multi Master I2C bus.
I’ve used up to three Masters at the same time. More should be possible.
Do not try to exeed the cable length over 1m and use shielded cables.
The following description was once written for the student.

The Mars Bus System is based on the I²C (I2C or TWI) bus. This is natively supported by the microcontrollers used one Arduino boards. In addition many sensors and actors use this bus for communication. Each device one the bus needs an unique address.
The communication on the bus is usually organized by one master MCU. All other members on the I²C bus are slaves and talk only to the bus if they were asked to do by the master. This way it is ensured only one MCU will write Data to the bus at a time.
If you have to design a attachment for the Mars that only responses to the bus you dont have to care about the following information. As said before, the I²C bus was made for one master only. However, some of the already installed MCUs in the MARS and maybe the MCU used by your group need to be I²C Masters. To ensure there wont be two Masters starting a communication at the same time, the bus needs to be reserved by pulling a busyline via a resistor high (5V). This busyline is usually held low with a resistor to GND. If An MCU wants to start writing to the bus, it checks the voltage of the busyline. If the voltage is lower 1V the MCU pulls the busyline via the internal pull-up resistor high. Then the MCU waits a short time and checks the busyline again. If the voltage of the busyline is lower 3V no other MCU reserved the bus and the MCU starts to write Data to the I²C bus. If the voltage is higher, it deactivates its pull-up and waits for a random time before it tries again.
Please note that this procedure is blocking all other functions. While this procedure is executed all other function wait.

We do use the folling functions for the Masters. The Slaves don’t need a special code.

boolean I2Creservieren () {		   //Function to reserve the bus
    while (1) {
    if (analogRead(A2) <= 200) {         	   //Checks the voltage of the busyline
      pinMode(A2, INPUT_PULLUP);                 //Activates the internal pull-up resistor(30k - 33k)
      delayMicroseconds(100);                    //Waits until the busyline adapted the new voltage
      if (analogRead(A2) <= 540){                //Checks the busyline again
         return (1);}                            //The function returns 1 after a successful transmission
      else{                                      //In case two masters tried to reserve the bus
         pinMode(A2, INPUT);                     //Deactivates the internal pull-up resistor
         delayMicroseconds(random(100, 1000));}} //Waits a random short time
    else{                                        //In case the Busyline was reserve from the beginning
        pinMode(A2, INPUT);}                     //Deactivates the internal pull-up resistor

To release the bus:

boolean I2Cfreigeben() {		   //Function to release the bus
  pinMode(A2, INPUT);
  return (1);

If you now want to send data it looks like this:

Wire.beginTransmission(10); // transmit to device #10
Wire.endTransmission();    // stop transmitting