我在板子上要使用PB11作为外部中断,使用stm32f10x_stdperiphere_library
在例子程序中只找到了使用PA3 PA4的,这些线可以直接挂在EXTI3 EXTI4中断上。
在STM32F10X的中断向量表中,在EXTI9-5 和EXTI15-10 看来我只能用EXTI15-10了。
附上初始化程序
void ShuttleKeyInit(void){
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
HT_STM_KEYInit(KNOBRIGHT);
/* Enable GPIOD clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
/* Configure PB.11 as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource11);
// Configure EXTI Line11 to generate an interrupt on falling edge
EXTI_InitStructure.EXTI_Line = EXTI_Line11;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable the EXTI15_10 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //EXTI15_10_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
中断服务程序
/*******************************************************************************
* Function Name : EXTI3_IRQHandler
* Description : This function handles External interrupt Line 3 request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line11) != RESET)
{
// DISABLE_PB11_INT;
if(HT_STM_KEYRead(KNOBRIGHT))
g_Shuttle = LEFTTURN;
else
g_Shuttle = RIGHTTURN;
EXTI_ClearITPendingBit(EXTI_Line11);
}
}
中断服务程序要力求精简,不然会死机。没搞明白是为什么。
文章评论(0条评论)
登录后参与讨论