CrossRoads:
It wakes up from sleep with external interrupts.
Do you have the interrupts pulled high with the internal pullups, and have interrupt 0 or 1 attached and set to trigger low?Here's all the pieces I found I needed, in IDE -0023 anyway. Have not tried it in 1.0 or 1.0.1
#include <avr/sleep.h> // powerdown library
#include <avr/interrupt.h> // interrupts library
int pin2 = 2; // Int0 interrupt pin
byte sleep_flag;
//***************************************************
// * Name: pin2Interrupt, "ISR" to run when interrupted in Sleep Mode
void pin2Interrupt()
{
/* This brings us back from sleep. */
}
//***************************************************
// * Name: enterSleep
void enterSleep()
{
/* Setup pin2 as an interrupt and attach handler. /
attachInterrupt(0, pin2Interrupt, LOW);
delay(50); // need this?
/ the sleep modes
SLEEP_MODE_IDLE - the least power savings
SLEEP_MODE_ADC
SLEEP_MODE_PWR_SAVE
SLEEP_MODE_STANDBY
SLEEP_MODE_PWR_DOWN - the most power savings
*/
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // setting up for sleep ...
sleep_enable(); // setting up for sleep ...
// Disable ADC
ADCSRA &= ~(1 << ADEN);
// Power down functions
PRR = 0xFF;
sleep_mode(); // now goes to Sleep and waits for the interrupt
/* The program will continue from here after the interrupt. */
detachInterrupt(0); //disable interrupts
// Power up functions
PRR = 0x00;
/* First thing to do is disable sleep. */
sleep_disable();
// then go to the void Loop()
}
// ***********************************************************************
// set up the pins as Inputs, Outputs, etc.
void setup()
{
/* Setup the pin directions, write inputs High to turn on internal pullups */
pinMode(pin2, INPUT); // our sleep interrupt pin
digitalWrite(pin2, HIGH);
} // end of void Setup()
// ***********************************************************************
// Main loop for reading the keypad and sending the button pushed out
// (with a unique address to be added eventually by reading 0-F from currently unused pins)
void loop()
{
// your code here to decide to go to sleep, lets say it sets a flag
if (sleep_flag == 1){
// Serial.println("Sleep"); // for debug only
enterSleep(); // call Sleep function to put us out
// THE PROGRAM CONTINUEs FROM HERE after waking up in enterSleep()
} // end of checking to go to sleep
} // end of void loop
Thanks for the input, it looks like this did it
// Disable ADC
ADCSRA &= ~(1 << ADEN);
// Power down functions
PRR = 0xFF;
This line was not in there but it needs to be turned back on also when it wakes.
ADCSRA |= (1 << ADEN);