I2C multimaster active address detection

hello,

I am trying to impliment a multimaster situation where the code will do one with when my other device is on and functioning, or do another when it is either off or disconnected.

I was using my code combined with the i2c scanner code found here
http://playground.arduino.cc/Main/I2cScanner

Here is part of my code to which this pertains.

#include <Wire.h>

#define THIS_ADDRESS 0x9
#define OTHER_ADDRESS 0x8

void setup() {
    Serial.begin(9600);
        
    Wire.begin(THIS_ADDRESS);  //begin I2C data transmission
    Wire.onReceive(receiveState);  //what to do if an I2C transmission is recieved
}

void loop(){
    transmitState(A,B,C)
}

void transmitState(int Channel, int State, int event){
    byte error = 1;
    byte sendState[3];
    
    sendState[0] = event;
    sendState[1] = Channel;
    sendState[2] = State;
    Wire.beginTransmission(OTHER_ADDRESS);
    error = Wire.endTransmission();  //this is where is freezes
    delay(10);
    
    if(error == 0){
      Wire.beginTransmission(OTHER_ADDRESS);
      Wire.write(sendState,3);
      Wire.endTransmission();
      Serial.println("transmission complete");
      error = 1;
    }
    
    else{
      Serial.println("Other Device absent");
    }
}

The i2c scanner finds my other arduino just fine on its own. By when i use the code in this fashion, it has the problem.

Thank you in advance for anyhelp you can provide

The Wire library does not support multimaster I2C configurations. What are you trying to achieve?

It supports it just fine http://michael.bouvy.net/blog/en/2013/05/25/arduino-multi-master-to-master-i2c/

My situation, needs two devices in to different locations (which are communicating via I2C over 4 fiber optic cables.)

Each has the ability to set and read states of push button switches and update a read out, as well as the solenoid valves they are each connected to.

This aspect works flawlesly.

The issue at hand, is running code which only runs when an I2C device is detected.

In the I2c scanner code, error = wire.endTransmission() ends on its own if no device was detected (ie my other arduino is powered off) and the loop keeps going.

Now when I try to use the error codes essentially If error does not equal 0 no device is connected dont do stuff If it does equal 0 then a device is connected and send the data before ending.

the issue comes into play when a device is not connected, with the I2C Scanner code placed into my code it freezes on End Transmission, While the I2c scanner code working on its own does not freeze.

I suppose a solution here, could be to just add two more fibers with constant light sources and detect them using some of my other I/O pins. But id rather not nee 6 fibes.

It supports it just fine http://michael.bouvy.net/blog/en/2013/05/25/arduino-multi-master-to-master-i2c/

This is not what multimaster means. It's just having two masters on the same bus which are sometimes sending some data. What happens if both masters start sending at the same time? If you can live with these race conditions this may be fine for you but it's not what I2C multimaster means.

ends on its own if no device was detected (ie my other arduino is powered off) and the loop keeps going.

Powered down is not the same as not connected. How have you wired the two Arduinos? Do you have schematics of your setup? How do the I2C signals translate to your fiber signals? Do you use hardware that knows the I2C protocol and translates that correctly into optical signals? How does that work with clock stretching? How did you find out where the code freezes?