Maximum Sleep!

Hello!

I would like to have my AtMega328P (on a breadboard) go into maximum sleep (duhn duhn duuuhhh!)

Could I skip all of the macros and libraries by just doing this?

byte temp=ADCSRA;

ADCSRA=0;//Disable ADC (must do this before next line)
PRR=0b1101111;//Disable All Peripherals (except for the "reserved" bit)

//Do normal <avr/sleep.h> stuff, go into SLEEP_MODE_PWR_DOWN

//Upon wakeup (via LOW interrupt):
ADCSRA=temp;
PRR=0;

//Re-init SPI, UART and I2C busses

A lot of the things this sleeps are not available in the avr/sleep library and would require other libraries.

Is this code OK?

Thanks!

Yeah - assuming the interrupts are enabled properly and stuff like that.

Cool!
Thank you!

Ya, I never use libraries for sleep.

Also, is there anything also I can (reversibly) turn off to save power?

Study this comprehensive guide to sleep and power reduction for AtMega cpus.

is there anything also I can (reversibly) turn off to save power?

Keep in mind that the Uno-like boards are NOT low-power, even with the processor completely removed. Similarly, for any real project, you need to keep an eye on things other than the AVR that are consuming power. An LED consumes FAR more power than a sleeping AVR, for example, even in the "less deep" sleep modes.

I'm using a breadboard 328P :slight_smile:

#include <avr/power.h>

PRR=0b1101111;//Disable All Peripherals (except for the "reserved" bit)

Replace with power_all_disable();

PRR=0;

Replace with power_all_enable();

You also haven’t turned off the analog comparator.

Oh, cool!
Also, I did turn off the ADC, right?

byte temp=ADCSRA;

ADCSRA=0;//Disable ADC (must do this before next line)

//.....

ADCSRA=temp

Thanks for telling me about those two macros, it'll greatly improve readability :slight_smile: