Interrupts not working when in sleep mode MCUdude/MegaCore atmega2560

Hello All,

I am using an alternative board: GitHub - MCUdude/MegaCore: Arduino hardware package for ATmega64, ATmega128, ATmega165, ATmega169, ATmega325, ATmega329, ATmega640, ATmega645, ATmega649, ATmega1280, ATmega1281, ATmega2560, ATmega2561, ATmega3250, ATmega3290, ATmega6450, ATmega6490, AT90CAN32, AT90CAN64 and AT90CAN128 Essentially the problem I am having is my interrupts are not working to wake an atmega2560 from sleep using the AVR core pinout, here is my test code:

#define alarm_pin 4
volatile int alarm_flag = 0;

void blink()
{
  noSleep(); //comment out for no-sleep example
  alarm_flag = 1;
  Serial.println("Alarm?");
}
void setup()
{

  Serial.begin(250000);
  Serial.println("Start");

  pinMode(alarm_pin, INPUT);           // set pin to input
  digitalWrite(alarm_pin, HIGH);       // turn on pullup resistors
}
void clr_alarm()
{
  detachInterrupt(alarm_pin);
  Serial.print("blink!\r\n");

  delay(1000);
  alarm_flag = 0;
    attachInterrupt(alarm_pin, blink, FALLING);
}
void loop()
{

  Serial.println("Loop");
  sleepMode(SLEEP_POWER_DOWN); //comment out for no-sleep example

  attachInterrupt(alarm_pin, blink, FALLING);
  Serial.flush(); //comment out for no-sleep example
  sleep(); //comment out for no-sleep example
  noSleep(); //comment out for no-sleep example

  delay(1000);
  if (alarm_flag == 1) {
    clr_alarm();
  }
}

The interrupt works if I remove the sleep lines, but won't wake the micro from sleep. I've tried interrupts INT4 and INT7, the board I am currently working on does not have any other INT pins broken out.

Thanks!

On the real Mega, pin 4 is not an external interrupt pin.

The attachInterrupt() function doesn't take a pin number.

So, exactly where have you connected the external interrupt source?

From GitHub - MCUdude/MegaCore: Arduino hardware package for ATmega64, ATmega128, ATmega165, ATmega169, ATmega325, ATmega329, ATmega640, ATmega645, ATmega649, ATmega1280, ATmega1281, ATmega2560, ATmega2561, ATmega3250, ATmega3290, ATmega6450, ATmega6490, AT90CAN32, AT90CAN64 and AT90CAN128

Refer to: https://camo.githubusercontent.com/111cedfdd3ed144af35375382874e3c54b4faf8f/687474703a2f2f692e696d6775722e636f6d2f446652376172442e6a7067

Pin 4 is INT4, so it is still interrupt 4 and should be fine to pass to attachinterrupt.