4.1 Example

The application note provides a code example about how to wake up ATmega328PB from the Power-down mode (which has the least consumption of all the sleep modes) by using USART. For other sleep modes, just change the argument in the set_sleep_mode() function. The source code is available for download from Atmel START. Here below is the main() function:
int main(void)
{
	power_reduction();
	uart_init();
	sei();
	while(1)
	{
		if(!ring_buffer_is_empty(&ring_buffer_in)){	
			usart_transmit( ring_buffer_get(&ring_buffer_in));
		} else {
			set_sleep_mode(SLEEP_MODE_PWR_DOWN);
			sleep_mode();
		}
	}
}