SAM L10/L11 External Interrupt Controller (EIC)

Last modified by Microchip on 2023/11/21 21:22

Overview

The External Interrupt Controller (EIC) allows external pins to be configured as interrupt lines. Each interrupt line can be individually masked and can generate an interrupt on rising, falling, or both edges or on high or low levels. Each external pin has a configurable filter to remove spikes. Each external pin can also be configured to be asynchronous in order to wake up the device from Sleep modes where all clocks have been disabled. External pins can also generate an event. Each external pin can be defined as secured or non-secured, whereas secured pins can only be handled by secure accesses. A separate non-maskable interrupt (NMI) is also supported. It has properties similar to the other external interrupts but is connected to the NMI request of the CPU, enabling it to interrupt any other Interrupt mode.

Back to top

Features

  • Up to eight external pins (EXTINTx), plus one non-maskable pin (NMI)
  • Dedicated, individually maskable interrupt for each pin
  • Interrupt on rising, falling, or both edges
  • Synchronous or asynchronous edge detection mode
  • Interrupt pin debouncing
  • Interrupt on high or low levels
  • Asynchronous interrupts for Sleep modes without clocks
  • Filtering of external pins
  • Event generation from EXTINTx
  • Selectable secured or non-secured attribution for each individual external pin (SAM L11)

Back to top

Block Diagram

SAM L10 external interrupt controller block diagram

Back to top

Principle of Operation

There are several interrupt request lines, at least one for the external interrupts (EXTINT) and one for Non-Maskable Interrupt (NMI). The EXTINT interrupt request line is connected to the interrupt controller. Using the EIC interrupt requires the interrupt controller to be configured first. The NMI interrupt request line is also connected to the interrupt controller but does not require the interrupt to be configured. The events are connected to the Event System. Using the events requires the Event System to be configured first.

The EIC detects edge or level conditions to generate interrupts to the CPU interrupt controller or events to the Event System. Each external interrupt pin (EXTINT) can be filtered using majority vote filtering, clocked by GCLK_EIC or by CLK_ULP32K.

The EIC is enabled by writing a 1 to the Enable bit in the Control A register (CTRLA.ENABLE). The EIC is disabled by writing CTRLA.ENABLE to 0. The EIC is reset by setting the Software Reset bit in the Control register (CTRLA.SWRST). All registers in the EIC will be reset to their initial state, and the EIC will be disabled.

The EIC must be initialized in the following order:

  1. Enable CLK_EIC_APB
  2. If required, configure the NMI by writing the Non-Maskable Interrupt Control Register (NMICTRL)
  3. Enable GCLK_EIC or CLK_ULP32K when one of the following configurations is selected:
    • the NMI uses edge detection or filtering
    • one EXTINT uses filtering
    • one EXTINT uses synchronous edge detection
    • one EXTINT uses debouncing
  4. Configure the EIC input sense and filtering by writing the Configuration n register (CONFIG).
  5. Optionally, enable the Asynchronous mode.
  6. Optionally, enable the Debouncer mode.
  7. Enable the EIC by writing a 1 to CTRLA.ENABLE.

​GCLK_EIC is used when a frequency higher than 32 kHz is required for filtering. CLK_ULP32K is recommended when power consumption is the priority. For CLK_ULP32K write a 1 to the Clock Selection bit in the Control A register (CTRLA.CKSEL).

The following bits are enable-protected, meaning that they can only be written when the EIC is disabled (CTRLA.ENABLE=0):

  • Clock Selection bit in Control A register (CTRLA.CKSEL)

The following registers are enable-protected:

  • Event Control register (EVCTRL)
  • Configuration n register (CONFIG)
  • External Interrupt Asynchronous Mode Register (ASYNCH)
  • Debouncer Enable register (DEBOUNCEN)
  • Debounce Prescaler register (DPRESCALER)

Enable-protected bits in the CTRLA register can be written at the same time when setting CTRLA.ENABLE to 1, but not at the same time as CTRLA.ENABLE is being cleared. Enable protection is denoted by the "Enable-Protected" property in the register description.

​Refer to the "EIC – External Interrupt Controller" chapter from the product data sheet for more details.

Back to top

SAM L10 Code Example

/***
 *** The Example has no copyright and can be used by anyone.
 *** The following example is based on Device File Package
 *** required to compile the macro definitions used.
 *** The Device File Package is available by downloading Atmel Studio 7.
 ***/

 
/***
 *** In this Example the External Interrupt Controller 
 *** is configured to detect Falling edge on EXTINT[2] (PA02),
 *** with a deboucing filter enabled.
 *** 
 *** 
 ***/

void EIC_2_Handler(void)
{
    /*** Clear EIC Flag ***/
    EIC->INTFLAG.reg |= EIC_INTFLAG_EXTINT(1<<2);    
}
 
void eic_init(void)
{
    /*** Detect Falling edge on EXTINT[2] (PA02) ***/
    EIC->CONFIG[0].reg = (uint32_t)(EIC_CONFIG_SENSE2_FALL | EIC_CONFIG_SENSE3_FALL);
    EIC->ASYNCH.reg = (EIC_ASYNCH_ASYNCH(1<<2));
 
    /*** Configure Debounce ***/
    EIC->DEBOUNCEN.reg = (EIC_DEBOUNCEN_DEBOUNCEN(1<<2));
    EIC->DPRESCALER.reg = (EIC_DPRESCALER_TICKON|EIC_DPRESCALER_STATES0|EIC_DPRESCALER_PRESCALER0(7));
 
    /*** Enable interrupt on EXTINT[2] (PA02) ***/
    EIC->INTENSET.reg = (EIC_INTENSET_EXTINT((1<<2)));
 
    /*** Enable EIC interrupt at core level ***/
    NVIC_EnableIRQ(EIC_2_IRQn);
 
    /*** Set EXTINT[1] Interrupt at core level ***/
    NVIC_SetTargetState(EIC_1_IRQn);
}
 
void secure_eic_enable(void)
{
    /*Enable EIC Peripheral */
    while(EIC->SYNCBUSY.bit.ENABLE);
    EIC->CTRLA.reg |= EIC_CTRLA_ENABLE;
}

Back to top

SAM L11 Code Example

/***
 *** The Example has no copyright and can be used by anyone.
 *** The following example is based on Device File Package
 *** required to compile the macro definitions used.
 *** The Device File Package is avaiblable by downloading Atmel Studio 7.
 ***/

 
/***
 *** In this Example the External Interrupt Controller 
 *** is configured to detect Falling edge on EXTINT[2] (PA02),
 *** with a deboucing filter enabled.
 *** The SAM L11 example uses the Mixed Secure Peripheral usage
 *** EIC_SEC.
 ***/

void EIC_2_Handler(void)
{
    /*** Clear EIC Flag ***/
    EIC_SEC->INTFLAG.reg |= EIC_INTFLAG_EXTINT(1<<2);
 
}
 
void secure_eic_init(void)
{
    /*** Detect Falling edge on EXTINT[2] (PA02) ***/
    EIC_SEC->CONFIG[0].reg = (uint32_t)(EIC_CONFIG_SENSE2_FALL | EIC_CONFIG_SENSE3_FALL);
    EIC_SEC->ASYNCH.reg = (EIC_ASYNCH_ASYNCH(1<<2));
 
    /*** Configure Debounce ***/
    EIC_SEC->DEBOUNCEN.reg = (EIC_DEBOUNCEN_DEBOUNCEN(1<<2));
    EIC_SEC->DPRESCALER.reg = (EIC_DPRESCALER_TICKON|EIC_DPRESCALER_STATES0|EIC_DPRESCALER_PRESCALER0(7));
 
    /*** Enable interrupt on EXTINT[2] (PA02) ***/
    EIC_SEC->INTENSET.reg = (EIC_INTENSET_EXTINT((1<<2)));
 
    /*** Enable EIC_SEC interrupt at core level ***/
    NVIC_EnableIRQ(EIC_2_IRQn);
 
    /*** Set EIC EXTINT[1] as non secure interrupt (Mix-Secure Use ***/
    EIC_SEC->NONSEC.reg = (EIC_NONSEC_EXTINT(1<<1));
    EIC_SEC->NSCHK.reg = (EIC_NSCHK_EXTINT(1<<1));
 
    /*** Set EXTINT[1] Interrupt as Non-Secure at core level ***/
    NVIC_SetTargetState(EIC_1_IRQn);
}
 
void secure_eic_enable(void)
{
    /*** Enable EIC Peripheral ***/
    while(EIC_SEC->SYNCBUSY.bit.ENABLE);
    EIC_SEC->CTRLA.reg |= EIC_CTRLA_ENABLE;
}

Back to top