By chance, when I was browsing the materials, I suddenly saw that there was a function in the external interrupt routine of Jihai:
APM_MINI_PBInit(BUTTON_KEY2, BUTTON_MODE_EINT);
APM_MINI_PBInit(BUTTON_KEY1, BUTTON_MODE_EINT);
I was so excited at that time, I thought that just this one sentence was enough to declare that this pin was an external interrupt.
But when I traced it, I found that it was just a complicated function. I was disappointed and wanted to rewrite this function.
By the way, evaluate the board in your hand.
The rewritten function is as follows:
void APM_Init(ButtonMode_TypeDef Button_Mode)
{
GPIO_Config_T GPIO_configStruct;
EINT_Config_T EINT_configStruct;
/** Enable the BUTTON Clock */
RCM_EnableAHB1PeriphClock(RCM_AHB1_PERIPH_GPIOC);
/** Configure Button pin as input floating */
GPIO_ConfigStructInit(&GPIO_configStruct);
GPIO_configStruct.mode = GPIO_MODE_IN;
GPIO_configStruct.pin = GPIO_PIN_10|GPIO_PIN_11;
GPIO_configStruct.pupd = GPIO_PUPD_UP;
GPIO_Config(GPIOC, &GPIO_configStruct);
if (Button_Mode == BUTTON_MODE_EINT)
{
/** Enable the SYSCFG Clock */
RCM_EnableAPB2PeriphClock(RCM_APB2_PERIPH_SYSCFG);
/** Reset the SYSCFG Periph */
SYSCFG_Reset();
/** Connect Button EINT Line to Button GPIO Pin */
SYSCFG_ConfigEINTLine(SYSCFG_PORT_GPIOC, SYSCFG_PIN_10);
SYSCFG_ConfigEINTLine(SYSCFG_PORT_GPIOC, SYSCFG_PIN_11);
/** Configure Button EINT line */
EINT_configStruct.line =EINT_LINE_10;
EINT_configStruct.mode = EINT_MODE_INTERRUPT;
EINT_configStruct.trigger = EINT_TRIGGER_FALLING;
EINT_configStruct.lineCmd = ENABLE;
EINT_Config(&EINT_configStruct);
EINT_configStruct.line =EINT_LINE_11;
EINT_configStruct.mode = EINT_MODE_INTERRUPT;
EINT_configStruct.trigger = EINT_TRIGGER_FALLING;
EINT_configStruct.lineCmd = ENABLE;
EINT_Config(&EINT_configStruct);
/** Enable and set Button EINT Interrupt to the lowest priority */
NVIC_EnableIRQRequest(EINT15_10_IRQn, 0x0f, 0x0f);
}
}
At the same time, add the interrupt function in apm32F4xx_int.c:
void EINT15_10_IRQHandler(void)
{
if(EINT_ReadIntFlag(EINT_LINE_10))
{
GPIO_ToggleBit(GPIOE,GPIO_PIN_5);
/**Clear EINT_LINE0 interrupt flag*/
EINT_ClearIntFlag(EINT_LINE_10);
}
if(EINT_ReadIntFlag(EINT_LINE_11))
{
GPIO_ToggleBit(GPIOE,GPIO_PIN_6);
/**Clear EINT_LINE0 interrupt flag*/
EINT_ClearIntFlag(EINT_LINE_11);
}
}
The main function is as follows:
int main(void)
{
// APM_MINI_LEDInit(LED2);
// APM_MINI_LEDInit(LED3);
GPIO_Config_T configStruct;
RCM_EnableAHB1PeriphClock(RCM_AHB1_PERIPH_GPIOE );
/** Configure the GPIO_LED pin */
GPIO_ConfigStructInit(&configStruct);
configStruct.pin = GPIO_PIN_5|GPIO_PIN_6;
configStruct.mode = GPIO_MODE_OUT;
configStruct.speed = GPIO_SPEED_50MHz;
GPIO_Config(GPIOE, &configStruct);
APM_Init(BUTTON_MODE_EINT);
while (1)
{
SysTick_Delay_ms(1000);
GPIO_ToggleBit(GPIOE,GPIO_PIN_5);
GPIO_ToggleBit(GPIOE,GPIO_PIN_6);
}
}
Of course, you have to adjust the corresponding header files during compilation.
The results are as follows:
476702518