Microchip® Advanced Software Framework

Quick Start Guide for EXTINT - Basic

The supported board list:

  • SAM D20 Xplained Pro
  • SAM D21 Xplained Pro
  • SAM R21 Xplained Pro
  • SAM L21 Xplained Pro
  • SAM L22 Xplained Pro
  • SAM DA1 Xplained Pro
  • SAM C21 Xplained Pro
  • SAM HA1G16A Xplained Pro

In this use case, the EXTINT module is configured for:

  • External interrupt channel connected to the board LED is used
  • External interrupt channel is configured to detect both input signal edges

This use case configures a physical I/O pin of the device so that it is routed to a logical External Interrupt Controller channel to detect rising and falling edges of the incoming signal.

When the board button is pressed, the board LED will light up. When the board button is released, the LED will turn off.

Setup

Prerequisites

There are no special setup requirements for this use-case.

Code

Copy-paste the following setup code to your user application:

{
struct extint_chan_conf config_extint_chan;
extint_chan_get_config_defaults(&config_extint_chan);
config_extint_chan.gpio_pin = BUTTON_0_EIC_PIN;
config_extint_chan.gpio_pin_mux = BUTTON_0_EIC_MUX;
config_extint_chan.gpio_pin_pull = EXTINT_PULL_UP;
config_extint_chan.detection_criteria = EXTINT_DETECT_BOTH;
extint_chan_set_config(BUTTON_0_EIC_LINE, &config_extint_chan);
}

Add to user application initialization (typically the start of main()):

Workflow

  1. Create an EXTINT module channel configuration struct, which can be filled out to adjust the configuration of a single external interrupt channel.
    struct extint_chan_conf config_extint_chan;
  2. Initialize the channel configuration struct with the module's default values.
    extint_chan_get_config_defaults(&config_extint_chan);
    Note
    This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
  3. Adjust the configuration struct to configure the pin MUX (to route the desired physical pin to the logical channel) to the board button, and to configure the channel to detect both rising and falling edges.
    config_extint_chan.gpio_pin = BUTTON_0_EIC_PIN;
    config_extint_chan.gpio_pin_mux = BUTTON_0_EIC_MUX;
    config_extint_chan.gpio_pin_pull = EXTINT_PULL_UP;
    config_extint_chan.detection_criteria = EXTINT_DETECT_BOTH;
  4. Configure external interrupt channel with the desired channel settings.
    extint_chan_set_config(BUTTON_0_EIC_LINE, &config_extint_chan);

Use Case

Code

Copy-paste the following code to your user application:

while (true) {
if (extint_chan_is_detected(BUTTON_0_EIC_LINE)) {
// Do something in response to EXTINT edge detection
bool button_pin_state = port_pin_get_input_level(BUTTON_0_PIN);
port_pin_set_output_level(LED_0_PIN, button_pin_state);
extint_chan_clear_detected(BUTTON_0_EIC_LINE);
}
}

Workflow

  1. Read in the current external interrupt channel state to see if an edge has been detected.
    if (extint_chan_is_detected(BUTTON_0_EIC_LINE)) {
  2. Read in the new physical button state and mirror it on the board LED.
    // Do something in response to EXTINT edge detection
    bool button_pin_state = port_pin_get_input_level(BUTTON_0_PIN);
    port_pin_set_output_level(LED_0_PIN, button_pin_state);
  3. Clear the detection state of the external interrupt channel so that it is ready to detect a future falling edge.
    extint_chan_clear_detected(BUTTON_0_EIC_LINE);