stm32F4的NVIC和中断
来源:互联网 发布:office2016软件下载 编辑:程序博客网 时间:2024/06/06 00:01
The total number of interrupt lines supported by an implementation, defined in groups of 32. That is, the total number of interrupt lines is up to (32*(INTLINESNUM+1)). However, the absolute maximum number of interrupts is 496, corresponding to the INTLINESNUM value 0b1111.
Cortex-M4 support a maximum of 240 external interrupts, so the absolute maximum number for it is b0111
Software Triggered Interrupt Register, STIR
Purpose: Provides a mechanism for software to generate an interrupt.
Usage constraints: This register applies to implemented external interrupts only.
INTID, bits[8:0]: Indicates the interrupt to be triggered. The value written is (ExceptionNumber - 16).
Interrupt Set-Enable Registers, NVIC_ISER0-NVIC_ISER15
Purpose: Enables, or reads the enable state of a group of interrupts.
SETENA, bits[m] For register NVIC_ISERn, enables or shows the current enabled state of interrupt (m+(32*n)):
0 On reads, interrupt disabled.
On writes, no effect.
1 On reads, interrupt enabled.
On writes, enable interrupt.
m takes the values from 31 to 0, except for NVIC_ISER15, where:
• m takes the values from 15 to 0.
• Register bits[31:16] are reserved, RAZ/WI.
Software can enable multiple interrupts in a single write to NVIC_ISERn.
Interrupt Clear-Enable Registers, NVIC_ICER0-NVIC_ICER15
Purpose: Disables, or reads the enable state of, a group of registers.
Usage constraints: NVIC_ICERn[31:0] are the clear-enable bits for interrupts (31+(32*n)) - (32*n). When n=15, bits[31:16] are reserved.
CLRENA, bits[m] For register NVIC_ICERn, disables or shows the current enabled state of interrupt (m+(32*n)):
0 On reads, interrupt disabled.
On writes, no effect.
1 On reads, interrupt enabled.
On writes, disable interrupt.
m takes the values from 31 to 0, except for NVIC_ICER15, where:
• m takes the values from 15 to 0.
• Register bits[31:16] are reserved, RAZ/WI.
Software can disable multiple interrupts in a single write to NVIC_ICERn.
Interrupt Set-Pending Registers, NVIC_ISPR0-NVIC_ISPR15
Purpose: For a group of interrupts, changes interrupt status to pending, or shows the current pending status.
Interrupt Clear-Pending Registers, NVIC_ICPR0-NVIC_ICPR15
Purpose: For a group of interrupts, clears the interrupt pending status, or shows the current pending status.
note: The ways to set these registers are similar to the ways to set NVIC_ISER and NVIC_ICER. So detailed descriptions are omitted in this blog.
Interrupt Active Bit Registers, NVIC_IABR0-NVIC_IABR15
Purpose: For a group of 32 interrupts, shows whether each interrupt is active.
ACTIVE, bits[m] For register NVIC_IABRn, shows whether interrupt (m+(32*n)) is active:
0 Interrupt not active.
1 Interrupt active.
m takes the values from 31 to 0, except for NVIC_IABR15, where:
• m takes the values from 15 to 0.
• Register bits[31:16] are reserved, RAZ/WI.
Interrupt Priority Registers, NVIC_IPR0-NVIC_IPR123
Purpose: Sets or reads interrupt priorities.
PRI_N3, bits[31:24] For register NVIC_IPRn, priority of interrupt number 4n+3.
PRI_N2, bits[23:16] For register NVIC_IPRn, priority of interrupt number 4n+2.
PRI_N1, bits[15:8] For register NVIC_IPRn, priority of interrupt number 4n+1.
PRI_N0, bits[7:0] For register NVIC_IPRn, priority of interrupt number 4n.
the downward description are specific for stm32 external interrupt/event controller.
External interrupt/event controller (EXTI)
The external interrupt/event controller consists of up to 23 edge detectors for generating event/interrupt requests. Each input line can be independently configured to select the type (interrupt or event) and the corresponding trigger event (rising or falling or both). Each line can also masked independently. A pending register maintains the status line of the interrupt requests.
The main features are the following:
• independent trigger and mask on each interrupt/event line
• dedicated status bit for each interrupt line
• generation of up to 23 software event/interrupt requests
• detection of external signals with a pulse width lower than the APB2 clock period. Refer to the electrical characteristics section of the STM32F4xx datasheets for details on this parameter.
the stm32 document also described the procedure of setting up an interrupt or an event.
Hardware interrupt selection
To configure the 23 lines as interrupt sources, use the following procedure:
• Configure the mask bits of the 23 interrupt lines (EXTI_IMR)
• Configure the Trigger selection bits of the interrupt lines (EXTI_RTSR and EXTI_FTSR)
• Configure the enable and mask bits that control the NVIC IRQ channel mapped to the external interrupt controller (EXTI) so that an interrupt coming from one of the 23 lines can be correctly acknowledged.
Hardware event selection
To configure the 23 lines as event sources, use the following procedure:
• Configure the mask bits of the 23 event lines (EXTI_EMR)
• Configure the Trigger selection bits of the event lines (EXTI_RTSR and EXTI_FTSR)
Software interrupt/event selection
The 23 lines can be configured as software interrupt/event lines. The following is the procedure to generate a software interrupt.
• Configure the mask bits of the 23 interrupt/event lines (EXTI_IMR, EXTI_EMR)
• Set the required bit in the software interrupt register (EXTI_SWIER)
Interrupt mask register (EXTI_IMR)
Bits 31:23 Reserved, must be kept at reset value.
Bits 22:0 MRx: Interrupt mask on line x
0: Interrupt request from line x is masked
1: Interrupt request from line x is not masked
Event mask register (EXTI_EMR)
Bits 31:23 Reserved, must be kept at reset value.
Bits 22:0 MRx: Event mask on line x
0: Event request from line x is masked
1: Event request from line x is not masked
Rising trigger selection register (EXTI_RTSR)
Bits 31:23 Reserved, must be kept at reset value.
Bits 22:0 TRx: Rising trigger event configuration bit of line x
0: Rising trigger disabled (for Event and Interrupt) for input line
1: Rising trigger enabled (for Event and Interrupt) for input line
Falling trigger selection register (EXTI_FTSR)
Bits 31:23 Reserved, must be kept at reset value.
Bits 22:0 TRx: Falling trigger event configuration bit of line x
0: Falling trigger disabled (for Event and Interrupt) for input line
1: Falling trigger enabled (for Event and Interrupt) for input line.
Software interrupt event register (EXTI_SWIER)
Bits 31:23 Reserved, must be kept at reset value.
Bits 22:0 SWIERx: Software Interrupt on line x
If interrupt are enabled on line x in the EXTI_IMR register, writing '1' to SWIERx bit when it is set at '0' sets the corresponding pending bit in the EXTI_PR register, thus resulting in an interrupt request generation. This bit is cleared by clearing the corresponding bit in EXTI_PR (by writing a 1 to the bit).
Pending register (EXTI_PR)
Bits 31:23 Reserved, must be kept at reset value.
Bits 22:0 PRx: Pending bit
0: No trigger request occurred
1: selected trigger request occurred
This bit is set when the selected edge event arrives on the external interrupt line. This bit is cleared by programming it to ‘1’.
In addition to these configurations, we also need to connect EXTI Lines to the corrected pins, using external interrupt configuration register.
There are four of these registers and each is responsible for 4 EXTI lines. And each EXTI line is also connected to a corresponding pin. And which GPIO is used is defined by the value in theses registers. For example, when we need to enable the interrupt of PA2. we should to write the 0000 to the EXIT3 field in the SYSCFG_EXTICR1.
I only put one register map in this blog.
SYSCFG external interrupt configuration register 1
Bits 31:16 Reserved, must be kept at reset value.
Bits 15:0 EXTIx[3:0]: EXTI x configuration (x = 0 to 3)
These bits are written by software to select the source input for the EXTIx external interrupt.
0000: PA[x] pin
0001: PB[x] pin
0010: PC[x] pin
0011: PD[x] pin
0100: PE[x] pin
0101: PF[x] pin
0110: PG[x] pin
0111: PH[x] pin
1000: PI[x] pin
依据说明中的流程下面将说明一下stm32库中的开启中断的步骤和库的实现
•在开启中断之前我们必须配置相关的GPIO pin为输入。
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_Init(GPIOA, &GPIO_InitStructure);GPIO_Init()将设置GPIOA的MODER为input,SPEED,然后PuPd为无上下拉电阻。
•连接EXTI line和相关pin口
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);它将设置SYSCFG
void SYSCFG_EXTILineConfig(uint8_t EXTI_PortSourceGPIOx, uint8_t EXTI_PinSourcex){ uint32_t tmp = 0x00; /* Check the parameters */ assert_param(IS_EXTI_PORT_SOURCE(EXTI_PortSourceGPIOx)); assert_param(IS_EXTI_PIN_SOURCE(EXTI_PinSourcex)); tmp = ((uint32_t)0x0F) << (0x04 * (EXTI_PinSourcex & (uint8_t)0x03)); SYSCFG->EXTICR[EXTI_PinSourcex >> 0x02] &= ~tmp; SYSCFG->EXTICR[EXTI_PinSourcex >> 0x02] |= (((uint32_t)EXTI_PortSourceGPIOx) << (0x04 * (EXTI_PinSourcex & (uint8_t)0x03)));}
• Configure the mask bits of the 23 interrupt lines (EXTI_IMR)
• Configure the Trigger selection bits of the interrupt lines (EXTI_RTSR and EXTI_FTSR)
/* Configure EXTI Line0 */ EXTI_InitStructure.EXTI_Line = EXTI_Line0; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure);EXTI_Init()将设置EXTI_IMR,开启相关外部中断的mask bit, 设置EXTI_RTSR and/or EXTI_FTSR,来指定何种边沿触发中断。
• Configure the enable and mask bits that control the NVIC IRQ channel mapped to the external interrupt controller (EXTI) so that an interrupt coming from one of the 23 lines can be correctly acknowledged.
/* Enable and set EXTI Line0 Interrupt to the lowest priority */ NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);NVIC_Init()将设置NVIC相关的寄存器。
void EXTI0_IRQHandler(void){ if(EXTI_GetITStatus(EXTI_Line0) != RESET) { /* Toggle LED4 */ STM_EVAL_LEDToggle(LED4); /* Clear the EXTI line 0 pending bit */ EXTI_ClearITPendingBit(EXTI_Line0); }}
- stm32F4的NVIC和中断
- NVIC 的抢占中断和响应中断
- STM32F4设置NVIC中断优先级分组
- STM32的NVIC和中断的总结
- STM32F4——NVIC中断优先级及外部中断
- STM32的嵌套中断系统NVIC和RCC详细整理
- NVIC中断
- STM32F4中断抢占优先级和响应优先级的概念
- STM32中EXTI(外部中断)和NVIC(嵌套向量中断)的关系
- STM32F4使用FreeRTOS的中断
- STM32F4使用FreeRTOS的中断
- STM32 对于NVIC中断优先级的设置
- stm32 中断嵌套NVIC的理解
- MCU程序设计之STM32F10X的中断NVIC
- 嵌套的向量式中断控制器(NVIC)
- 实例理解stm32的中断控制NVIC
- SRAM初始化和设置NVIC中断表偏移
- NVIC中断使能
- 复数模板类1
- Mac和Ubuntu下安装Erlang
- Hibernate的session.flush做了什么呢【1】
- Fragment不同操作的生命周期
- 电影记录
- stm32F4的NVIC和中断
- Hibernate的session.flush做了什么呢【2】
- 真正的成功来自于爱和热情
- linux下安装jdk
- 如何查看端口+如何关闭开放端口
- Linux学习笔记1
- ONOS 南向抽象层分析
- Android 自定义标题栏(title栏)
- hibernate-悲观锁与乐观锁