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

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.

NVIC_IRQChannel

Here you tell for which interrupt you will set settings.

NVIC_IRQChannelPreemptionPriority

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.

NVIC_IRQChannelSubPriority

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.

NVIC_IRQChannelCmd

With that you select if interrupt is enabled or disabled.

Example

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

 

tilz0R

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...