stm32 外部PB8中斷
一、初始化該引腳時鐘
本文引用地址:http://www.ex-cimer.com/article/201807/383652.htmRCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB ,ENABLE);
二、初始化該引腳為外部中斷
void GPIO_Config_Init(void)
{
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //PB8 dog_wake
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, GPIO_InitStructure);
}
三、初始化外部中斷函數(shù)
void EXTI_Config_Init(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
EXTI_ClearITPendingBit(EXTI_Line8);//
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource8);//
EXTI_InitStructure.EXTI_Line=EXTI_Line8; //
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //
EXTI_InitStructure.EXTI_LineCmd = ENABLE;//
EXTI_Init(EXTI_InitStructure);
}
四、初始化中斷向量表
void NVIC_Config_Init(void)
{
NVIC_InitStructure.NVIC_IRQChannel =EXTI9_5_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;//ÇÀÕ¼ÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;//×ÓÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//ʹÄÜÍⲿÖжÏͨµÀ
NVIC_Init(NVIC_InitStructure);
}
五、編寫外部中斷函數(shù)
void EXTI9_5_IRQHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line8) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line8); //
GPIO_SetBits(GPIOB,GPIO_Pin_9);
delay_ms(10);
GPIO_ResetBits(GPIOB,GPIO_Pin_9);
}
}
- STM32單片機(jī)中文官網(wǎng)
- STM32單片機(jī)官方開發(fā)工具
- STM32單片機(jī)參考設(shè)計
評論