Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interrupts not working when in sleep mode #84

Closed
Mr-Newlove opened this issue Mar 7, 2018 · 3 comments
Closed

Interrupts not working when in sleep mode #84

Mr-Newlove opened this issue Mar 7, 2018 · 3 comments

Comments

@Mr-Newlove
Copy link

Mr-Newlove commented Mar 7, 2018

Hello,

Essentially the problem I am having is my interrupts are not working to wake a 2560 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.

@MCUdude
Copy link
Owner

MCUdude commented Mar 8, 2018

Does it work if you use the regular Arduino Mega 2560 as your target? We need to figure out if this is a MegaCore related issue or not

try using the avr/sleep.h library and see if you van get it working. There's plenty of tutorials out there. I'm om vacation right now, so I'm not able to help you at the moment.

@Mr-Newlove
Copy link
Author

After quite a bit of fiddling with both using avr/sleep.h and the sleep options through this board functions, I have narrowed it down to be specifically the FALLING condition.

Works fine when using LOW but not FALLING. Both using your MegaCore and the standard 2560 board. I can make that work.

So I can say conclusively it is not limited to your board lib, where should I file a bug report on this for presumably the default lib? Unless my understanding of the chip is wrong, but this FALLING edge interrupt should still work in sleep, but I may be wrong.

@MCUdude
Copy link
Owner

MCUdude commented Mar 9, 2018

I think the best place to report/discuss this may be over at the avrfreaks forum. Thats where all the big guys hang out 😉

There might be a silicon bug inside the ATmega2560, so post the date code of the chip along with your question.

@MCUdude MCUdude closed this as completed Mar 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants