How do I use a button to wake up an atmega32?
\$\overline{\mathsf{RESET}}\$

A push button from \$\overline{\mathsf{RESET}}\$ to ground is the easiest way, but it forgets current state entirely.

Interrupts

For interrupts to work you need a pin that attributed as INTn and for ATmega32 you are limited to PB2, PD2 or PD3. Not all sleep modes support waking up by external interrupt and different sleep modes support edge or level triggered interrupts.

For thes pins you have to:


Enable the interrupt in the General Interrupt Control Register GICR;
Review the Interrupt Sense Control bits in MCUCR and MCUCSR.


You don't need to add an complete ISR (interrupt service routine) if all you want to do is wake up and continue where you left off, but you shouldn't rely on the default vector. It depends on the compiler what actually happens on a bad interrupt. Refer here for the name of the interrupt vector to use.

ISR() { INT0_vect , EMPTY_INTERRUPT };


For details check the chapter titled 'External Interrupts' in the ATmega32 datasheet.

For a button to ground on PD2 (INT0) code might look a bit like this (untested):

DDRD  &amp;= ~ ( 1 &lt;&lt; PD2 );    // Configure PD2 as input
PORTB |=   ( 1 &lt;&lt; PD2 );    // Enable pull up resistor
// MCUCR default triggers on LOW level. Changing to edge trigger requires different sleep mode to wake up.
GICR  |=   ( 1 &lt;&lt; INT0 );   // Enable INT0