Disable 2iC interrupts on Pins 21/20

Hi there,

I'm using 2iC to communicate between an Arduino Nano and Mega 2560 v3.

The communication works great using the wire library as per the instructions here:

However, as part of my project I am putting my Arduino mega to sleep using code and methods used here:
https://playground.arduino.cc/Learning/arduinoSleepCode

The mega goes to sleep with no issues and prior to working with two arduinos linked together and 2iC, I have successfully set up an interrupt on Pin 2 of the Mega. That works fine.

However, I have noticed that pins 20 (SDA) and 21 (SCL) being used for 2iC communication using wire act as an interrupt. Whenever something is sent from the Nano, the mega wakes up every time.

This is not desired as I wish to control the interrupt only on pin 2, and not 20/21.

I have found no way to disable interrupts on 21/20 & 2ic. I can disable interrupts entirely with noInterrupts(); but if I do that then none of the interrupts will work to disable sleep.

I have searched hard but cannot find a way to disable interrupts for the 2iC pins on the mega but not have it mess with 2iC communication when the Mega is in fact awake.

Can anyone shed some light on what I might be able to do here?

I have tried detaching interrupts with:
detachInterrupt(20);
detachInterrupt(21);

and

detachInterrupt(2);
detachInterrupt(3);
(As INT.2 and INT.3 on the mega refer to pin 20 & 21)

but this doesn't change anything. The Mega always wakes up as soon as the Nano transmits 2iC data.

It should also be noted that I tried disabling the Pin 2 interrupt also incase there was some weird conflict there, and even without attaching any interrupts, 2iC still wakes up the Mega.

You can try to disable the I2C interrupts in the TWCR register before sleep, and enable again after wakeup.

Sounds like you are trying to have a I2C slave ignore it's master? That's not a very good idea!

Mark

holmes4:
Sounds like you are trying to have a I2C slave ignore it's master? That's not a very good idea!

Mark

Actually, I want the master to ignore it's slave. The nano is the slave, the mega is the master.

Because the Mega needs to sleep and ignore 2iC messages during that time, this is why I need this outcome.

DrDiettrich:
You can try to disable the I2C interrupts in the TWCR register before sleep, and enable again after wakeup.

How can I achieve this, or a good place to find information on how?

An I2C slave sends data only when asked for by a master. It's not required to disable the master, if it's the only master on the bus. If your slave broadcasts without being asked for, then change that behaviour.