Add Idle Sleep Mode

In this application the CPU is needed only to set up the peripherals and to perform the data processing. In order to reduce power consumption the CPU can be put into sleep whenever it is not in use. In Idle mode the CPU and Flash program memory is stopped, while the peripheral clock and peripheral modules are kept running.

To enter Idle sleep mode, the following steps need to be performed:

Strictly speaking it does not need to disable the sleep function. It is however good coding practice to do this to ensure that software bugs leading to runaway code do not accidentally put the CPU back in sleep mode.

The AVR GCC Toolchain has predefined macros and functions available to control the sleep modes of the AVR. In this application the following macro and functions are used:

set_sleep_mode(mode)

void sleep_enable(void)

void sleep_cpu(void)

void sleep_disable(void)

To use these functions, include the "avr/sleep.h" header file in your project.