NVIC_Instruct_NVIC_Irgchanne=EXTI9_5 IRON改为寄存器版本
时间: 2023-10-08 19:06:56 浏览: 104
将NVIC_Instruct_NVIC_Irgchanne函数中的以下代码:
```
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_InitStruct.NVIC_IRQChannel = EXTI9_5_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
```
改为以下寄存器版本的代码:
```
NVIC->IP[EXTI9_5_IRQn] = 0x00; //设置中断抢占优先级为0
NVIC->ISER[EXTI9_5_IRQn >> 5] = (uint32_t)1 << (EXTI9_5_IRQn & 0x1F); //使能中断
```
注意,这里只是将代码转换为寄存器版本,没有改变任何功能。
相关问题
在保持原来的代码逻辑的条件下,根据STM32F407的特性,把下面STM32F1的代码移植到STM32F407。void ExtiGpioInit(void) { GPIO_InitTypeDef GPIO_InitStruct; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO, ENABLE); GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_5 ; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOC, &GPIO_InitStruct); } void ExtiNvicInit(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn ; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void ExtiModeInit(void) { EXTI_InitTypeDef EXTI_InitStructure; GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource4); EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_Line = EXTI_Line4; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource5); EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_Line = EXTI_Line5; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); }
void ExtiGpioInit(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_5 ;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC, &GPIO_InitStruct);
}
void ExtiNvicInit(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void ExtiModeInit(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource4);
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_Line = EXTI_Line4;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource5);
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_Line = EXTI_Line5;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
EXTI_InitTypeDef EXTI_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; KEY_Init(); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource2); EXTI_InitStructure.EXTI_Line=EXTI_Line2; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x03; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); 解释每一句代码
这段代码是针对单片机开发的,主要是为了实现对外部中断的响应。下面是每一句代码的解释:
1. EXTI_InitTypeDef EXTI_InitStructure;:定义一个EXTI_InitTypeDef类型的结构体变量EXTI_InitStructure,用于配置外部中断线的触发模式、中断线号等参数。
2. NVIC_InitTypeDef NVIC_InitStructure;:定义一个NVIC_InitTypeDef类型的结构体变量NVIC_InitStructure,用于配置中断优先级等参数。
3. KEY_Init();:初始化按键,具体内容未知。
4. RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);:开启AFIO时钟,该时钟控制着GPIO的复用功能。
5. GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource2);:配置GPIOE的Pin2引脚为外部中断线2。
6. EXTI_InitStructure.EXTI_Line=EXTI_Line2;:设置外部中断线号为2。
7. EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;:设置外部中断模式为中断模式。
8. EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;:设置触发模式为下降沿触发。
9. EXTI_InitStructure.EXTI_LineCmd = ENABLE;:使能外部中断线。
10. EXTI_Init(&EXTI_InitStructure);:将以上配置应用到外部中断线2上。
11. NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;:设置中断通道为外部中断线0,实际上应该是写成EXTI2_IRQn。
12. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;:设置中断优先级为2。
13. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x03;:设置中断响应优先级为3。
14. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;:使能中断通道。
15. NVIC_Init(&NVIC_InitStructure);:将以上配置应用到中断控制器上。
阅读全文