So after doing some reading both the forums, and various internet sites, I think I have an understanding of reducing power by putting things to sleep, but I'd appreciate if someone could confirm my understanding.
I've got the following code:
void sleepNow()
{
/* Now is the time to set the sleep mode. In the Atmega8 datasheet
* http://www.atmel.com/dyn/resources/prod_documents/doc2486.pdf on page 35
* there is a list of sleep modes which explains which clocks and
* wake up sources are available in which sleep modus.
*
* In the avr/sleep.h file, the call names of these sleep modus are to be found:
*
* The 5 different modes are:
* 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
*
* the power reduction management <avr/power.h> is described in
* http://www.nongnu.org/avr-libc/user-manual/group__avr__power.html
*/
set_sleep_mode(SLEEP_MODE_IDLE); // sleep mode is set here
sleep_enable(); // enables the sleep bit in the mcucr register
// so sleep is possible. just a safety pin
power_adc_disable();
power_spi_disable();
power_timer0_disable();
power_timer1_disable();
power_timer2_disable();
power_twi_disable();
sleep_mode(); // here the device is actually put to sleep!!
// THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
sleep_disable(); // first thing after waking from sleep:
// disable sleep...
power_all_enable();
}
So my understanding is to enable power saving features, I call "sleepnow();" where I want the chip to go to sleep.
What I'm questioning is how I implement this. I'd like the device to go into power saving mode if no data is received on a SoftSerial line (tied to pins 5 and 8). Since this is not a UART line, is there a way to tie an interrupt to a non interrupt (INT0,1) pin? I cannot use INT0-1 because they're already being used. if not, since this is the lowest power saving mode, would something like the following work?:
if (Bluetooth.available()) //NewSoftSerial on Digital pins 5 and 8)
{
.
.
.
}
else
{
delay (10000); //Delay 10 seconds if Bluetooth connection is not available
SleepNow(); //start power saving
};
If not, is there a way of modifying the sleep routine to save as much power as possible? I'm not using the ADC or SPI features, and I need the Softserial available immediately if data comes in (can't wait for it to wake up). An alternative I suppose would be to attach an interrupt to an unused pin, and then tie the bluetooth modules status led (goes high when a link is established) and use that to wake the processor as soon as a connection is made....
Thanks.