void NVICInit(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
#ifdef VECT_TAB_RAM
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);// 使能AFIO
/**********配置优先级组****************************/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置中断优先级
/*允许EXTI4中断 */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource0);
EXTI_ClearITPendingBit(EXTI_Line0);
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //上升沿触发
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_LineCmd = ENABLE; //中断线使能
EXTI_Init(&EXTI_InitStructure); //初始化外部中断
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM4_IRQHandler(void)
{
if (TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET) //检查TIM1更新中断发生与否
{
TIM_ClearITPendingBit(TIM4, TIM_IT_Update); //清除TIMx更新中断标志
TIM_ITConfig(TIM4, TIM_IT_Update, DISABLE); //关定时器4中断
EXTI_InitStructure.EXTI_LineCmd = DISABLE; //中断线使能
}
}
这是我外部中断函数的初始化部分,我是想在定时器4里面关闭外部中断,结果就是关不了,请高手指点一下
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
/**
* @brief This function handles EXTI line0 interrupt.
*/
void EXTI0_IRQHandler(void)
{
/* USER CODE BEGIN EXTI0_IRQn 0 */
//这段必须要在 HAL_GPIO_EXTI_IRQHandler 函数前面,不然不能达到目的
while (!HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0));
HAL_Delay(5);
while (!HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0));
HAL_Delay(5);
/* USER CODE END EXTI0_IRQn 0 */
HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_0);
/* USER CODE BEGIN EXTI0_IRQn 1 */
/* USER CODE END EXTI0_IRQn 1 */
}
//外部中断0服务程序
void EXTIX_Init(u8 x)
......
if(x == 1)
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能外部中断通道
if(x == 0)
NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE; //使能外部中断通道
NVIC_Init(&NVIC_InitStructure);
即需要重新初始化。。。方法有点笨,可是我是一直这样用的
一周热门 更多>