0
0
ARM Architectureknowledge~5 mins

NVIC (Nested Vectored Interrupt Controller) in ARM Architecture

Choose your learning style9 modes available
Introduction

The NVIC helps the processor handle many interrupt signals quickly and in order. It decides which interrupt to handle first so the system works smoothly.

When multiple hardware devices need the processor's attention at the same time.
When you want to prioritize certain tasks over others in an embedded system.
When you need fast and efficient response to external events like button presses or sensor signals.
When designing real-time systems that must react quickly to important signals.
When managing interrupts in ARM Cortex-M microcontrollers.
Core Concept
ARM Architecture
NVIC_EnableIRQ(IRQn_Type IRQn);
NVIC_DisableIRQ(IRQn_Type IRQn);
NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority);
NVIC_GetPriority(IRQn_Type IRQn);
NVIC_ClearPendingIRQ(IRQn_Type IRQn);
NVIC_SetPendingIRQ(IRQn_Type IRQn);

IRQn_Type is the interrupt number or name for a specific interrupt source.

Priority is usually a number where lower means higher priority.

Key Points
This enables the interrupt for Timer 2 so the processor can respond when Timer 2 triggers an interrupt.
ARM Architecture
NVIC_EnableIRQ(TIM2_IRQn);
This sets the priority of the USART1 interrupt to 1, making it higher priority than interrupts with larger numbers.
ARM Architecture
NVIC_SetPriority(USART1_IRQn, 1);
This disables the external interrupt line 0, so it will not trigger an interrupt.
ARM Architecture
NVIC_DisableIRQ(EXTI0_IRQn);
Detailed Explanation

This simple program enables the interrupt for an external line (like a button). It sets the priority so the processor knows how important this interrupt is compared to others. The main loop waits for interrupts to happen.

ARM Architecture
#include "stm32f4xx.h"

int main(void) {
    // Enable interrupt for external line 0 (e.g., a button press)
    NVIC_EnableIRQ(EXTI0_IRQn);

    // Set priority to 2 (lower number means higher priority)
    NVIC_SetPriority(EXTI0_IRQn, 2);

    // Main loop
    while (1) {
        // Wait for interrupts
    }
    return 0;
}
OutputSuccess
Important Notes

NVIC is part of ARM Cortex-M processors and manages interrupts efficiently.

Lower priority numbers mean higher priority interrupts.

Always enable the interrupt and set its priority before expecting it to work.

Summary

NVIC controls how the processor handles multiple interrupts.

It allows setting priorities to decide which interrupt to handle first.

Use NVIC functions to enable, disable, and prioritize interrupts in ARM Cortex-M systems.