Atmega1284p does not sleep (mighty core)

Hi,

First of all, i'm using the mighty core bootloader on the Mega1284p.

I want to put the atmega to sleep
for this i'm using

void sleeper(){

	//attachInterrupt(digitalPinToInterrupt(HW_KEYSWITCH), key_isr, LOW); //attach interrupt to key switch
	Serial.flush();
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
	sleep_enable();
	sleep_mode();
	sleep_disable();
	power_all_enable();
	Serial.println("WAKE!");

}

But it does not work!

First of all i had the Interrupt on, but to make sure its not a hardware issue, i've commented it out.
In the current case the Atmega should fall into sleep mode and NEVER wake up again, since nothing will disable the sleep mode (right?). But "Wake" gets printed out on the Serial port... so its not sleeping.
But magically the current drops from around 9mA to 6.5mA when the function hits sleep_mode. But it won't rise again.

Any idea what i'm doing wrong?

Also the same issue with the other sleep modes.. :frowning:

Post complete code! The error is probably at some other location. Please post schematics of your board, there might be another source for an interrupt to wake your AVR.

#define HW_KEYSWITCH 11
bool isr_flag_1 = false;

void setup(){

pinMode(HW_KEYSWITCH,INPUT);
Serial.begin(9600);
Serial.println("start..");
}

void loop(){
sleeper();

}

void sleeper(){

	//attachInterrupt(digitalPinToInterrupt(HW_KEYSWITCH), key_isr, LOW); //attach interrupt to key switch
	Serial.flush();
	set_sleep_mode(SLEEP_MODE_PWR_DOWN);
	sleep_enable();
	sleep_mode();
	sleep_disable();
	power_all_enable();
	Serial.println("WAKE!");

}

void key_isr(){
	detachInterrupt(1);
	sleep_disable();
	Serial.println("Key Pressed");
	isr_flag_1 = true;
}

That code doesn't compile on my IDE.

BTW:

void key_isr(){
	detachInterrupt(1);
	sleep_disable();
	Serial.println("Key Pressed");
	isr_flag_1 = true;
}

Calling any method of Serial inside an ISR is a very bad idea. The serial interface depends on interrupts and during an ISR interrupts are disabled.