INT6 on Arduino Leonardo / ATMega32U4

The documentation for Arduino's attachInterrupt function lists the pins for the four interrupts available on an Arduino Leonardo. But the Leonardo uses the ATMega32U4, which has a fifth external interrupt (called external interrupt 6, or INT6, just to be confusing). INT6 is not available from the attachInterrupt() function, but is available if you access it directly via the registers EICRB (External Interrupt Control Register B) and EIMSK (External Interrupt Mask Register):

EICRB |= (1<<ISC60)|(1<<ISC61); // sets the interrupt type
EIMSK |= (1<<INT6); // activates the interrupt

For more information, see sections 11.0.2 and 11.0.3 of the ATMega32U4 datasheet.

To set the interrupt function, define it in the normal AVR way:

ISR(INT6_vect) {
  // interrupt code goes here
}

The interrupt type is described in Table 11-3 of the datasheet, and is similar to interrupts 0 - 3:

ISC61   ISC60   Triggered By
0 0 INT6 low
0 1 Any logical change on INT6
1 0 Falling edge between two INT6 samples
1 1 Rising edge between two INT6 samples


For INT6 to work, it requires the AVR I/O clock to be present, unlike INT0 - INT3.

INT6 uses Port E Pin 6 (PE6), which corresponds to Digital Pin 7 on the Leonardo.