STM32F4 NVIC or Nested Vector Interrupt Controller

Interrupts are important in microcontrollers. WIth them you are able to stop executing main program and jump to some predefined area if there is something important.

I already used interrupts in my USART library. There is an interrupt called each time data arrive to MCU.

Defferent peripheral can trigger interrupt, like data come to USART, ADC finished conversion, timer overflow, and more more.


NVIC or Nested Vector Interrupt Controller is used to dinamically tell which interrupt is more important and for enabling or disabling interrupts. It supports up to 256 different interrupt vectors.

NVIC Structure

This is defined in “misc.h” file in CMSIS pack.

NVIC structure accept 4 parameters.


Here you tell for which interrupt you will set settings.


With this parameter you set interrupt priority, number from 0x00 to 0x0F. Let’s say we have to use USART receive interrupt and ADC conversion finished interrupt. USART is more important than ADC, so USART will have lower number than ADC.


With this parameter you set interrupt priority, number from 0x00 to 0x0F. Let’s say you have 2 USARTs enabled, but USART1 is more important than USART2. So USART1 will have lower number than USART2.


With that you select if interrupt is enabled or disabled.


Handle interrupts

For handling interrupts we can use special defined function names. In our example, for handle USART1 interrupts, we can use something like this



Owner of this site. Application engineer, currently employed by STMicroelectronics. Exploring latest technologies and owner of different libraries posted on Github.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!