Go Down

Topic: Using the Xbee to sleep Arduino (Read 2 times) previous topic - next topic

CrossRoads

Not sure you can wake up from sleep with PCINT. Think you need to use one of the external INTs for that.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Jack Christensen


Not sure you can wake up from sleep with PCINT. Think you need to use one of the external INTs for that.


Yep, have a project that does exactly that. From the datasheet:

Quote
10.5 Power-down Mode
When the SM2...0 bits are written to 010, the SLEEP instruction makes the MCU enter Powerdown
mode. In this mode, the external Oscillator is stopped, while the external interrupts, the 2-
wire Serial Interface address watch, and the Watchdog continue operating (if enabled). Only an
External Reset, a Watchdog System Reset, a Watchdog Interrupt, a Brown-out Reset, a 2-wire
Serial Interface address match, an external level interrupt on INT0 or INT1, or a pin change
interrupt can wake up the MCU. This sleep mode basically halts all generated clocks, allowing
operation of asynchronous modules only.


INT0, INT1, and pin change interrupts will wake from any of the sleep modes.
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

CrossRoads

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

jahnavi

Hi,

Can you please  send me an example code that uses pin interchange to wake up the arduino.

Thanku very much

Jack Christensen


Hi,

Can you please  send me an example code that uses pin interchange to wake up the arduino.

Thanku very much


Code: [Select]
#include <avr/sleep.h>

void setup(void)
{
}

void loop(void)
{
}

void goToSleep()
{
   byte adcsra, mcucr1, mcucr2;

   sleep_enable();
   set_sleep_mode(SLEEP_MODE_PWR_DOWN);
   PCICR = _BV(PCIE1);            //enable pin change interrupts 8-14
   PCMSK1 = _BV(PCINT8) | _BV(PCINT11) | _BV(PCINT12) | _BV(PCINT13);    //enable PCINT8,11,12,13 (PC0,3,4,5)
   adcsra = ADCSRA;               //save the ADC Control and Status Register A
   ADCSRA = 0;                    //disable ADC
   cli();
   mcucr1 = MCUCR | _BV(BODS) | _BV(BODSE);  //turn off the brown-out detector
   mcucr2 = mcucr1 & ~_BV(BODSE);
   MCUCR = mcucr1;                //timed sequence
   MCUCR = mcucr2;                //BODS stays active for 3 cycles, sleep instruction must be executed while it's active
   sei();                         //ensure interrupts enabled so we can wake up again
   sleep_cpu();                   //go to sleep
                                  //wake up here
   PCICR = 0x00;                  //disable pin change interrupts 8-14
   PCMSK1 = 0x00;
   sleep_disable();
   ADCSRA = adcsra;               //restore ADCSRA
}

ISR(PCINT1_vect)
{
   PCICR = 0x00;                  //disable pin change interrupts 8-14
   PCMSK1 = 0x00;
}
MCP79411/12 RTC ... "One Million Ohms" ATtiny kit ... available at http://www.tindie.com/stores/JChristensen/

Go Up