Go Down

Topic: Interrupts not working when in sleep mode MCUdude/MegaCore atmega2560 (Read 704 times) previous topic - next topic

mr_newlove

Hello All,

I am using an alternative board: https://github.com/MCUdude/MegaCore 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:

Code: [Select]
#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!

PaulS

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?
The art of getting good answers lies in asking good questions.

mr_newlove

From https://github.com/MCUdude/MegaCore

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.

Go Up