Skip to content

3. API Changes for XMega

bombasticbob edited this page Oct 27, 2014 · 34 revisions

A few APIs have changed, out of necessity, to support the XMega.

attachInterrupt(port, callback, mode);

  port is the I/O port and int number
  example: PORTC_INT0, PORTD_INT0, PORTR_INT1, etc.

  callback is a pointer to a user callback function

  mode (new) is a bit-flag indicating the following:
    trigger mode - LOW, HIGH, RISING, FALLING, CHANGE
    interrupt pin - INT_MODE_PIN_DEFAULT, INT_MODE_PIN0, etc.
    priority - INT_MODE_PRI_DEFAULT, INT_MODE_PRI_HIGH, etc.

typical usage:
    attachInterrupt(PORTD_INT0,
                          my_callback,
                          RISING
                          | INT_MODE_PIN_DEFAULT
                          | INT_MODE_PRI_DEFAULT);

The port (formerly 'interrupt number') is passed to 'detachInterrupt' and detaches ALL interrupts for that particular port and interrupt combination. Some CPUs have 2 interrupts per port, some only one. The first will be labeled 'INT0', and subsequent interrupts 'INT1', etc. Each port+interrupt combination can only have a single callback, so you should assign the callback and all of the interrupt pins at the same time. It will be up to the callback functino to determine which pins is responsible for the interrupt.

There is a small exception with hardware flow control, which manages its interrupts separately, in conjuction with 'attachInterrupt()' and 'detachInterrupt()' calls. It is possible to assign an interrupt on the same port as the hardware flow control pins, without interfering. However, its priority will not be lowered from 'HIGH'.


Clone this wiki locally