Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
NVIC Example

Purpose

This example shows how to use the NVIC especially nested and priority management.

Requirements

This example can be used with SAM4 evaluation kits.

Description

In this example, two interrupt sources will be configured. One is from User Button, and the other is from PIO output. They are called INT1 and INT2. INT1 is triggered by pressing user button #1, and INT2 is triggered by pressing user button #2.

In INT1 handler:

  • At the entrance, an enter message will be printed and LED1 will be turned on.
  • Then delay for a while.
  • At the exit, an exit message will be printed and LED1 will be turned off.

In INT2 handler:

  • At the entrance, an enter message will be printed and LED2 will be turned on.
  • Then delay for a while.
  • At the exit, an exit message will be printed and LED2 will be turned off.

Users can change the priorities of INT1 and INT2. Nest and priority features can be watched in terminal window or by LEDs.

Usage

  1. Build the program and download it into the evaluation board.
  2. On the computer, open and configure a terminal application (e.g., HyperTerminal on Microsoft Windows) with these settings:
    • 115200 bauds
    • 8 bits of data
    • No parity
    • 1 stop bit
    • No flow control
  3. In the terminal window, the following text should appear:
    -- Cortex-M4 NVIC Example --
    -- Compiled: xxx xx xxxx xx:xx:xx --
    Set INT1's priority higher than INT2.
    Menu:
    ===================================================
    1: Set INT2's priority higher than INT1.
    2: Set INT1's priority higher than INT2.
    h: Show this menu.
    ===================================================
    Press button USR-LEFT to trigger the interrupts.
  4. Choose options in the above menu to set interrupt priority.
  5. Press buttons to trigger the interrupts.
    If INT2's priority is higher than INT1's, the following text should appear in the terminal window:
    ===================================================
    Enter _Int1Handler.
    ***************************************************
    Enter _Int2Handler.
    Exit _Int2Handler.
    ***************************************************
    Exit _Int1Handler.
    ===================================================
    If INT1's priority is higher than INT2's, the following text should appear in the terminal window:
    ===================================================
    Enter _Int1Handler.
    Exit _Int1Handler.
    ===================================================
    ***************************************************
    Enter _Int2Handler.
    Exit _Int2Handler.
    ***************************************************
    The result is also shown by LEDs.

References