Using External Interrupts For Megaavr Devices
megaAVR Devices
Features
•
•
•
•
Flexible pin configuration
Synchronous and asynchronous interrupt sensing
Asynchronous wake-up signal to wake up from sleep modes
®
Driver source code included for Atmel ATmega2560
- Basic external interrupt usage on ATmega2560
- Nested external interrupt usage on ATmega2560
- Generating softwareinterrupt with external interrupt pin configured as output on
ATmega2560
- Using external interrupt to wake up device on ATmega2560
8-bit Atmel
Microcontrollers
Application Note
1 Introduction
This application note illustrates the functionality and configuration steps (usage) of
the external interrupts available on Atmel megaAVR® family of Atmel AVR®
Microcontrollers. The application notealso describes the points to be considered
while using a GPIO pin as an external interrupt source pin.
The example codes have been implemented on ATmega2560 device with Atmel
AVR Studio® 5 and tested on Atmel AVR STK®600 starter kit for functionality.
Rev. 8468A-AVR-11/11
2 External interrupt – overview
Interrupts are signals given to the CPU of the microcontroller unit, either frominternal
peripheral modules or from external pins of the MCU that alters the regular flow of the
program execution by making the CPU to make a jump to execute instruction routines
in some pre-defined location depending on the interrupt that occurred. Once the CPU
completes the routine, it gets back to the location from where it had made a jump.
These pre-defined locations are called as theinterrupt vector addresses or interrupt
vectors.
An interrupt causes the device to save its state of execution and start executing the
interrupt handler like for Atmel AVR Microcontrollers the PC register is the only
register that will be saved and the stack pointer register is updated on an event of an
interrupt. It is up to the user to save other registers like the status register, 32 generalpurpose registers (register file), on an event of an interrupt, if there is such a
requirement in the application.
The Interrupts are commonly used to save time (like multitasking) than the
conventional polling method (waiting for the event to occur indefinitely).
2.1 External interrupt vectors
The Atmel megaAVR supports several interrupt sources out of which external
interrupts aresignificant. The external interrupts can be triggered using two sets of
pins. INTn pins (ordinary external interrupt pins) and PCINTn pins (pin change
external interrupt pins). The ‘n’ varies from device to device and signifies the number
like INT0. Please refer to respective device datasheet for the specific values of n.
For Atmel ATmega2560 the numbers of external interrupt pins are as given below:1. INT7:0 Pins (with various input sense configurations).
2. Pin change interrupts pins (PCINT23:0).
Generally for each interrupt source there is an interrupt vector to which the program
execution control jumps, to execute the corresponding service routine. The interrupt
vectors for external interrupts on ATmega2560 are shown in Table 2-1. For device
specific interrupt vectors, please referto the respective datasheet.
Table 2-1. External interrupt vector address table.
Vector
no.
Program
address
Source
Port pins in
ATmega2560
Interrupt definitions
1
RESET
RESET
2
$0002
INT0
PD0
External Interrupt Request 0
3
$0004
INT1
PD1
External Interrupt Request 1
4
$0006
INT2
PD2
External Interrupt Request 2
5
$0008INT3
PD3
External Interrupt Request 3
6
$000A
INT4
PE4
External Interrupt Request 4
7
$000C
INT5
PE5
External Interrupt Request 5
8
2
$0000
External Pin, Power-on Reset,
Brown-out Reset,
Watchdog Reset, and JTAG AVR
Reset
$000E
INT6
PE6
External Interrupt Request 6
Atmel AVR1200
8468A-AVR-11/11
Atmel AVR1200
Vector
no....
Regístrate para leer el documento completo.