我用国民的N32G45XRL-STB开发板来配置按键中断,中断无法进入.代码如下:
宏定义:
#define KEY_INPUT_PORT_SOURCE GPIOA_PORT_SOURCE
#define KEY_INPUT_PIN_SOURCE GPIO_PIN_SOURCE6
#define KEY_INPUT_IRQn EXTI0_IRQn
#define KEY_INPUT_EXTI_LINE EXTI_LINE0
#define KEY_INPUT_IRQHandler EXTI0_IRQHandler
#define GroupB GPIOB
#define GroupA GPIOA
#define GreenLED_PIN GPIO_PIN_5
#define RedLED_PIN GPIO_PIN_8
#define KeyInput_Port GPIOA
#define KeyInput_Pin GPIO_PIN_6
main函数:
int main(void)
{
GPIO_int(GroupB,GreenLED_PIN);
// GPIO_int(GroupA,RedLED_PIN);
KeyInputExtiInit(KeyInput_Port,KeyInput_Pin);
while(1)
{
;
}
}
按键中断注册函数:
void KeyInputExtiInit(GPIO_Module* GPIOx, uint16_t Pin)
{
GPIO_InitType GPIO_InitStructure;
EXTI_InitType EXTI_InitStructure;
NVIC_InitType NVIC_InitStructure;
/* Check the parameters */
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
/* Enable the GPIO Clock */
if (GPIOx == GPIOA)
{
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
}
else if (GPIOx == GPIOB)
{
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE);
}
else if (GPIOx == GPIOC)
{
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOC, ENABLE);
}
else if (GPIOx == GPIOD)
{
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOD, ENABLE);
}
else if (GPIOx == GPIOE)
{
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOE, ENABLE);
}
else if (GPIOx == GPIOF)
{
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOF, ENABLE);
}
else
{
if (GPIOx == GPIOG)
{
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOG, ENABLE);
}
}
RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_AFIO, ENABLE);
/*Configure the GPIO pin as input floating*/
if (Pin <= GPIO_PIN_ALL)
{
GPIO_InitStructure.Pin = Pin;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitPeripheral(GPIOx, &GPIO_InitStructure);
}
/*Configure key EXTI Line to key input Pin*/
GPIO_ConfigEXTILine(KEY_INPUT_PORT_SOURCE, KEY_INPUT_PIN_SOURCE);
/*Configure key EXTI line*/
EXTI_InitStructure.EXTI_Line = KEY_INPUT_EXTI_LINE;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; // EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_InitPeripheral(&EXTI_InitStructure);
/*Set key input interrupt priority*/
NVIC_InitStructure.NVIC_IRQChannel = KEY_INPUT_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x05;//0x05;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;//0x0F;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
调试仿真程序,发现无法进行到中断回调函数中处理:
void KEY_INPUT_IRQHandler(void)
{
GPIO_SetBits(GPIOB,GPIO_PIN_5);
// if (RESET != EXTI_GetITStatus(KEY_INPUT_EXTI_LINE))
// {
// LedBlink(LED2_PORT, LED2_PIN);
// EXTI_ClrITPendBit(KEY_INPUT_EXTI_LINE);
// }
}
有谁可以帮忙看下问题.谢谢! |