-
Notifications
You must be signed in to change notification settings - Fork 17
Differences for the XMega implementation
There are a few API changes that had to be made to support the XMega processors.
For the XMega, the attachInterrupt function is now defined as follows:
void attachInterrupt(uint8_t interruptNum, void (*)(void), int mode);
For C++ code, the 'mode' parameter gets a default value of 0.
Typical usage:
attachInterrupt(PORTD_INT0, // the specific interrupt vector - see pins_arduino.h
my_callback, // user-defined callback function
RISING // interrupt mode (can be LOW, HIGH, RISING, FALLING, CHANGE)
| INT_MODE_PIN_DEFAULT // the pin(s) to assign to this interrupt, or default pin 2
| INT_MODE_PRI_DEFAULT); // interrupt priority, default is 'high' (optional)
The 'interruptNum' constants are in pins_arduino.h, typically defined similar to:
#define PORTD_INT0 0
#define PORTD_INT1 1
#define PORTC_INT0 2
#define PORTC_INT1 3
#define PORTE_INT0 4
#define PORTE_INT1 5
#define PORTA_INT0 6
#define PORTA_INT1 7
#define PORTB_INT0 8
#define PORTB_INT1 9
#define PORTR_INT0 10
#define PORTR_INT1 11
The constant 'EXTERNAL_NUM_INTERRUPTS' will equal the total number of available interrupts. Note that these constants vary from processor to processor. The E5 series only has 'INT0' interrupts, for example, and the A1(U) series has additional ports and interrupts.
The 'mode' parameter uses the following constants from 'Arduino.h':
#define INT_MODE_PRI_DEFAULT 0
#define INT_MODE_PRI_LOW 0x0040
#define INT_MODE_PRI_MED 0x0080
#define INT_MODE_PRI_HIGH 0x00c0
#define INT_MODE_PIN0 0x0100
#define INT_MODE_PIN1 0x0200
#define INT_MODE_PIN2 0x0400
#define INT_MODE_PIN3 0x0800
#define INT_MODE_PIN4 0x1000
#define INT_MODE_PIN5 0x2000
#define INT_MODE_PIN6 0x4000
#define INT_MODE_PIN7 0x8000
#define INT_MODE_PIN_DEFAULT 0
Multiple pins can be specified for interrupts. These are 'or'd with the following trigger types:
#define LOW 0x0
#define HIGH 0x1
#define CHANGE 2
#define FALLING 3
#define RISING 4
© 2015-2019 (and later) by S.F.T. Inc.
You may freely use this documentation as you see fit, provided that appropriate credit is made, similar to a BSD or MIT license.