"Embedded System Principles and Applications" | (g) interruption sort of knowledge

 

Index series: "Embedded Systems Principles and Applications" | Embedded Systems focuses sort of knowledge


 

table of Contents

 

 

 

What is interrupted

Process interrupt, the interrupt vector table

Interruption of the pros and cons

STM32 NVIC interrupt priority in processing

STM32 middle of the role of service functions and characteristics

Interrupt-related library function (interrupt channel, set priority packets)

External Interrupt / Event Controller features and how to use EXTI

The role of the volatile keyword, and using the interrupt example


 

What is interrupted

In short, an interrupt is to notify the CPU currently have an event occurs .

Interrupt source (interrupt request flag)

  It can trigger event interrupt. In general, interrupt sources and peripherals related. Each interrupt source has its corresponding interrupt flag. Thus, the general interrupt service routine corresponding to the final you want to interrupt flag.

Interrupt Mask

By setting the corresponding interrupt mask bit, the CPU is disabled in response to an interrupt, the interrupt mask to achieve.

 

Process interrupt, the interrupt vector table

Interrupt processing

STM32 interrupt vector table

STM32F103 corresponding to each interrupt entry address of the interrupt service routine stored in a unified STM32F103 the interrupt vector table. Interrupt vector table STM32F103 general in its memory the 0 address .

 

Interruption of the pros and cons

STM32 NVIC interrupt priority in processing

Nested Vectored Interrupt Controller NVIC

 NVIC integrated ARM Cortex-M3 core , the core is tightly coupled to the CM3Core central processor, in order to achieve low latency interrupt handling and efficiently handle late higher priority interrupt.

4-bit priority setting, having 16 programmable priority exception;

STM32中断优先级(分组)

STM32中断优先级,分为抢占优先级子优先级

STM32微控制器的每个中断源,有4位优先级(ARM Cortex-M3内核定义了8位,STM32微控制器只使用了其中的4位),具有16级可编程异常优先级。

用户可以根据实际应用需求通过编程设定4位优先级中抢占优先级的位数和子优先级的位数。

STM32中段服务函数的作用及其特点

 STM32所有的中断服务函数,在该微控制器所属产品系列的启动代码文件中都有预先定义

 

中断相关库函数(中断通道、优先级分组的设置)

NVIC_DeInit:将NVIC的寄存器恢复为复位启动时的默认值。

NVIC_PriorityGroupConfig:设置优先级分组。

NVIC_Init:根据NVIC_InitStruct中指定的参数初始化NVIC。

设置中断优先级

 /* Configure one bit for preemption priority */

  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//设置中断优先级组

  /* Enable the TIM2_IRQn Interrupt */

  NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; //设置TIM2_IRQn中断通道

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;  // 指定抢占式优先级别,可取0-7

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;  //子优先级为0

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;  //IRQ通道使能

  NVIC_Init(&NVIC_InitStructure);  //根据指定的参数初始化VIC寄存器

 

编写对应的中断服务程序

 

外部中断/事件控制器EXTI的特性及其使用方式

STM32F103的通用I/O引脚可以被直接映射为外部中断通道或事件输出,用于产生中断⁄事件请求。如何在通用I/O引脚上产生中断事件请求的呢?答案就是STM32微控制器另一个片上外设——外部中断∕事件控制器EXT

STM32微控制器的外部中断∕事件控制器EXTI,由19根外部输入线19个产生中断事件请求的边沿检测器APB外设接口等部分组成,除EXTI16(PVD输出)、EXTI17(RTC闹钟)和EXTI18(USB唤醒),0-15GPIO引脚相对应。

如果将STM32F103的I/O引脚映射为EXTI的外部中断∕事件输入线,必须将该引脚设置为输入模式

如果使用STM32F103引脚的外部中断∕事件映射功能,必须打开APB2总线上该引脚对应端口时钟以及AFIO功能时钟

EXTI特性

EXTI使用方式(使用GPIO引脚作为外部中断源时)

  1. GPIO引脚时钟打开,工作模式为输入(上拉或下拉)
  2. 要把GPIO和对应的中断线连接起来
  3. 设置中断的优先级

EXTI相关库函数

EXTI_DeInit:将EXTI寄存器恢复为复位时的默认值。

EXTI_Init:根据EXTI_InitStruct中指定的参数初始化EXTI。

EXTI_GetFlagStatus:检查指定的外部中断∕事件线的标志位。

EXTI_ClearFlag:清除指定外部中断∕事件线的标志位。

EXTI_GetITStatus:检查指定的外部中断∕事件线的触发请求发生与否。

EXTI_ClearITPendingBit:清除指定外部中断∕事件线的中断挂起位。

 

volatile关键字的作用,并使用中断举例

中断中的使用

 

 

 

发布了112 篇原创文章 · 获赞 975 · 访问量 22万+

Guess you like

Origin blog.csdn.net/qq_41523096/article/details/103788115