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!