1206 views|2 replies

1w

Posts

16

Resources
The OP
 

【Jihai APM32F407】9, External key interrupt [Copy link]

 

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


This post is from Domestic Chip Exchange

Latest reply

jiayou~   Details Published on 2023-6-12 19:37
Personal signaturehttp://shop34182318.taobao.com/
https://shop436095304.taobao.com/?spm=a230r.7195193.1997079397.37.69fe60dfT705yr
 
 

6831

Posts

11

Resources
2
 
There is no need to add de-shake, the effect is still very good, what a trick!
This post is from Domestic Chip Exchange
 
 
 

266

Posts

0

Resources
3
 

jiayou~

This post is from Domestic Chip Exchange
Personal signature

gitee/casy

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list