I2C question - onReceive in master?

I am trying to send a a message via I2C from a Mega to a Due over I2C when a sensor is triggered on the Mega.

I have the Due currently set as the master, and in my setup of the master, this is what I have:

void setup()
{
    Wire.begin(); // joining the I2C bus as a master
    Wire.onReceive(onReceive);
}

void onReceive(int howMany)
{
    Serial.println("received");

    while (Wire.available())
    {
        char c = Wire.read();
    }
}

And then in my Mega, I am trying to send a message to the master:

void setup()
{
    Wire.begin(1); // joining the I2C bus as a slave on address 1
}

void loop()
{
    Wire.beginTransmission(0);
    Wire.write("TEST");
    Wire.endTransmission(1);
	
    delay(10000);
}

The message "testing" is never triggered in the master. Now from what I understood, calling Wire.beginTransmission(0) would transmit a string back to the master. But that doesn't appear to be happening?

Can I not have an onReceive handler in the master? I may have up to 10 slave boards attached with 40+ sensors per board, so I don't want to have the master request the status of each sensor each iteration of its loop, but rather be interrupted when there is a change in a sensor status on one of the slaves.

What am I missing here? I am new to doing anything with I2C so forgive me if I missed the point here!

You should post up all the code not just a snippet that you think is relevant.

The code you show will never use the message "testing" as it does not exist. The receiving code does nothing with the data it recieves other than discard it so how can you be sure it is not received?

Hi mikeluken

If you want all of the slave boards to be able to initiate an I2C transfer to the master, and you don't want to use out-of-band signalling, then I think you need to use an I2C multi-master configuration. Your "slaves" would be the masters and your "master" would be the slave that they communicate with.

There is some information on this thread which may help: Arduino I2C Multi Master design - Interfacing - Arduino Forum

Regards

Ray