1729 views|4 replies

36

Posts

1

Resources
The OP
 

JHIHAI APM32E103VET6 Review: External Interrupt (EINT) [Copy link]

 

Based on the project established last time, we add the corresponding external interrupt code to realize the external interrupt of the button and control the on and off of the LED light. The following is the button schematic diagram. There are three buttons in total, namely reset, B1 and B2. We use B1, which is the button connected to PA0. When the button is pressed, it is at a low level. Therefore, we need to configure PA0 as a pull-up input in the program so that the IO port is at a high level when it is not pressed. According to this working principle, start to configure the relevant code.

1. Configure GPIO as pull-up input

#define KEY1_PIN GPIO_PIN_0

#define KEY1_PORT GPIOA

#define KEY1_PORT_CLK_ENABLE() RCM_EnableAPB2PeriphClock( RCM_APB2_PERIPH_GPIOA );

GPIO_Config_T s_GPIO_InitStruct = { 0 };

/* ---Config the Clock of the Gpios--- */

KEY1_PORT_CLK_ENABLE();

/* ---Config the Clock of the Afio--- */

RCM_EnableAPB2PeriphClock( RCM_APB2_PERIPH_AFIO );

/* ---Config Key1 pin Parameters--- */

s_GPIO_InitStruct.pin = KEY1_PIN;

s_GPIO_InitStruct.mode = GPIO_MODE_IN_PU; //Configure as pull-up input

GPIO_Config( KEY1_PORT, &s_GPIO_InitStruct );

2. Configure external interrupts

EINT_Config_T s_EINT_InitStruct = { 0 };

GPIO_ConfigEINTLine( GPIO_PORT_SOURCE_A, GPIO_PIN_SOURCE_0 ); //Configure external interrupt line to PA0

s_EINT_InitStruct.line = EINT_LINE_0;

s_EINT_InitStruct.lineCmd = ENABLE;

s_EINT_InitStruct.mode = EINT_MODE_INTERRUPT; //Interrupt mode

s_EINT_InitStruct.trigger = EINT_TRIGGER_FALLING; //Falling edge trigger

EINT_Config( &s_EINT_InitStruct );

NVIC_EnableIRQRequest( EINT0_IRQn, 1, 0 ); //Configure NVIC request

3. Write interrupt service function

void EINT0_IRQHandler( void )

{

if( RESET != EINT_ReadIntFlag( EINT_LINE_0 ) )

{

if( RESET == GPIO_ReadInputBit( KEY1_PORT, KEY1_PIN ) )

{

LED1_PORT->ODATA_B.ODATA8 ^= 1;

}

EINT_ClearIntFlag( EINT_LINE_0 );

}

}

1_APM32E103VET6_EINT.7z

569.73 KB, downloads: 0

This post is from Domestic Chip Exchange

Latest reply

Thanks for sharing, looking forward to the follow-up!   Details Published on 2022-9-15 23:05
 
 

6547

Posts

0

Resources
2
 

What to test after external interrupt evaluation

This post is from Domestic Chip Exchange

Comments

Serial Port  Details Published on 2022-9-14 11:13
 
 
 

36

Posts

1

Resources
3
 
Jacktang posted on 2022-9-14 07:19 What to test after external interrupt evaluation

Serial Port

This post is from Domestic Chip Exchange

Comments

Okay, looking forward to it   Details Published on 2022-9-15 07:08
 
 
 

6547

Posts

0

Resources
4
 

Okay, looking forward to it

This post is from Domestic Chip Exchange
 
 
 

7422

Posts

2

Resources
5
 

Thanks for sharing, looking forward to the follow-up!

This post is from Domestic Chip Exchange
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

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