4784 views|9 replies

606

Posts

20

Resources
The OP
 

【Wireless digital intercom based on GDF350】4. Big BUG of external interruption? [Copy link]

This post was last edited by ketose on 2018-10-1 20:05 Today I was setting up the buttons for the intercom. I wanted to use both buttons on the development board, but I encountered a big BUG in GD32. Is my level too low? Let's first look at the schematic diagram of the two buttons on the F350 development board. From the schematic diagram, the B2 button is connected to PA0, and the B3 button is connected to PB7. Okay, let's write some code to verify it:
  1. #include "gd32f3x0.h" // Device header int main() { //Enable GPIO clockrcu_periph_clock_enable(RCU_GPIOB); rcu_periph_clock_enable(RCU_GPIOA); //Set external interruptgpio_mode_set(GPIOA,GPIO_MODE_INPUT,GPIO_PUPD_NONE,GPIO_PIN_0); syscfg_exti_line_config(EXTI_SOURCE_GPIOA,EXTI_SOURCE_PIN0); exti_init(EXTI_0,EXTI_INTERRUPT,EXTI_TRIG_BOTH); gpio_mode_set(GPIOB,GPIO_MODE_INPUT,GPIO_PUPD_NONE,GPIO_PIN_7); syscfg_exti_line_config(EXTI_SOURCE_GPIOB,EXTI_SOURCE_PIN7); exti_init(EXTI_7,EXTI_INTERRUPT,EXTI_TRIG_BOTH); //Set the interrupt priority nvic_irq_enable(EXTI4_15_IRQn,0,1); nvic_irq_enable(EXTI0_1_IRQn,0,2); while(1) { //Verify if(gpio_input_bit_get(GPIOB,GPIO_PIN_7) == RESET) { gpio_input_bit_get(GPIOB,GPIO_PIN_7); } if(gpio_input_bit_get(GPIOA,GPIO_PIN_0) == RESET) { gpio_input_bit_get(GPIOA,GPIO_PIN_0); } } } void EXTI0_1_IRQHandler(void) { exti_interrupt_flag_clear(EXTI_0); } void EXTI4_15_IRQHandler(void) { exti_interrupt_flag_clear(EXTI_7); }
复制代码
As shown in the figure below, set a breakpoint: Debug the program, let the program run, and then press B2. The program will break at exti_interrupt_flag_clear(EXTI_0), and then continue to run. The program will then break at gpio_input_bit_get(GPIOA,GPIO_PIN_0); This is correct. Verify the B3 button. No matter how you press it, it will not break. It will only break gpio_input_bit_get(GPIOB,GPIO_PIN_7); With the same settings, why does the external interrupt of PB7 not work? Finally, the debugging found that the values of the registers EXTISS0-EXTISS3 cannot be set. That is to say, the external interrupts that GD32F350 can use are only PA0, PB0, PC0, PF0. If you want to use other pins... no chance! At the same time, I have a GD32F450 development board and did the same experiment. The result is the same. No way, I can't believe it. If there is a GD32 FAE in the forum, please come out and answer it.
This post is from GD32 MCU

Latest reply

/* enable the key clock */ rcu_periph_clock_enable(RCU_GPIOB); rcu_periph_clock_enable(RCU_CFGCMP); /* configure button pin as input */ gpio_mode_set(GPIOB, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_9); /* enable and set key EXTI interrupt to the lowest priority */ nvic_irq_ enable(EXTI4_15_IRQn, 2U, 0U); /* connect key EXTI line to key GPIO pin */ syscfg_exti_line_config(EXTI_SOURCE_GPIOB, EXTI_SOURCE_PIN9); /* configure key EXTI line */ exti_init(EXTI_9, EXTI_INTERRUPT, EXTI_TRIG_FALLING);复制代码B9 tested and available. The original poster's code seems to be missing rcu_periph_clock_enable(RCU_CFGCMP); this  Details Published on 2018-10-1 22:36
 

3414

Posts

0

Resources
2
 
I have tested that there are other interrupt sources available. You can try the code again...
This post is from GD32 MCU

Comments

Is there something wrong with my code?  Details Published on 2018-10-1 21:11
 
 
 

606

Posts

20

Resources
3
 
ljj3166 Published on 2018-10-1 20:20 I have tested that there are other interrupt sources available. The OP can code more...
Is there anything wrong with my code?
This post is from GD32 MCU
 
 
 

3414

Posts

0

Resources
4
 
I have used interrupt sources 0 and 1, but don't know about the others. Compare the three-way buttons. Only one key value may appear each time.
  1. #define WHEEL_KEY_UP_PIN GPIO_PIN_0 #define WHEEL_KEY_UP_GPIO_PORT GPIOB #define WHEEL_KEY_UP_GPIO_CLK RCU_GPIOB #define WHEEL_KEY_UP_EXTI_LINE EXTI_0 #define WHEEL_KEY_UP_EXTI_PORT_SOURCE EXTI_SOURCE_GPIOB #define WHEEL_KEY_UP_EXTI_PIN_SOURCE EXTI_SOURCE_PIN0 #define WHEEL_KEY_UP_EXTI_IRQn EXTI0_1_IRQn #define WHEEL_KEY_OK_PIN GPIO_PIN_1 #define WHEEL_KEY_OK_GPIO_PORT GPIOB #define WHEEL_KEY_OK_GPIO_CLK RCU_GPIOB #define WHEEL_KEY_OK_EXTI_LINE EXTI_1 #define WHEEL_KEY_OK_EXTI_PORT_SOURCE EXTI_SOURCE_GPIOB #define WHEEL_KEY_OK_EXTI_PIN_SOURCE EXTI_SOURCE_PIN1 #define WHEEL_KEY_OK_EXTI_IRQn EXTI0_1_IRQn #define WHEEL_KEY_DN_PIN GPIO_PIN_1 #define WHEEL_KEY_DN_GPIO_PORT GPIOA #define WHEEL_KEY_DN_GPIO_CLK RCU_GPIOA #define WHEEL_KEY_DN_EXTI_LINE EXTI_1 #define WHEEL_KEY_DN_EXTI_PORT_SOURCE EXTI_SOURCE_GPIOA #define WHEEL_KEY_DN_EXTI_PIN_SOURCE EXTI_SOURCE_PIN1 #define WHEEL_KEY_DN_EXTI_IRQn EXTI0_1_IRQn void WHEEL_KEY_INIT(void) { /* enable the key clock */ rcu_periph_clock_enable(WHEEL_KEY_UP_GPIO_CLK); rcu_periph_clock_enable(WHEEL_KEY_OK_GPIO_CLK); rcu_periph_clock_enable(WHEEL_KEY_DN_GPIO_CLK); rcu_periph_clock_enable(RCU_CFGCMP); /* configure button pin as input */ gpio_mode_set(WHEEL_KEY_UP_GPIO_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, WHEEL_KEY_UP_PIN); gpio_mode_set(WHEEL_KEY_OK_GPIO_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, WHEEL_KEY_OK_PIN); gpio_mode_set(WHEEL_KEY_DN_GPIO_PORT, GPIO_MODE_INPUT, GPIO_PUPD_NONE, WHEEL_KEY_DN_PIN); /* enable and set key EXTI interrupt to the lowest priority */ nvic_irq_enable(WHEEL_KEY_UP_EXTI_IRQn, 2U, 0U); nvic_irq_enable(WHEEL_KEY_OK_EXTI_IRQn, 2U, 0U); nvic_irq_enable(WHEEL_KEY_DN_EXTI_IRQn, 2U, 0U); /* connect key EXTI line to key GPIO pin */ syscfg_exti_line_config(WHEEL_KEY_UP_EXTI_PORT_SOURCE, WHEEL_KEY_UP_EXTI_PIN_SOURCE); syscfg_exti_line_config(WHEEL_KEY_OK_EXTI_PORT_SOURCE, WHEEL_KEY_OK_EXTI_PIN_SOURCE); syscfg_exti_line_config(WHEEL_KEY_DN_EXTI_PORT_SOURCE, WHEEL_KEY_DN_EXTI_PIN_SOURCE); /* configure key EXTI line */ exti_init(WHEEL_KEY_UP_EXTI_LINE, EXTI_INTERRUPT, EXTI_TRIG_FALLING); exti_interrupt_flag_clear(WHEEL_KEY_UP_EXTI_LINE); exti_init(WHEEL_KEY_OK_EXTI_LINE, EXTI_INTERRUPT, EXTI_TRIG_FALLING); exti_interrupt_flag_clear(WHEEL_KEY_OK_EXTI_LINE); exti_init(WHEEL_KEY_DN_EXTI_LINE, EXTI_INTERRUPT, EXTI_TRIG_FALLING); exti_interrupt_flag_clear(WHEEL_KEY_DN_EXTI_LINE); } void EXTI0_1_IRQHandler(void) { if (RESET != exti_interrupt_flag_get(WHEEL_KEY_UP_EXTI_LINE)) { wheel_key_up = true; exti_interrupt_flag_clear(WHEEL_KEY_UP_EXTI_LINE); } else {} if ((RESET != exti_interrupt_flag_get(WHEEL_KEY_OK_EXTI_LINE)) && !gpio_input_bit_get(WHEEL_KEY_OK_GPIO_PORT, WHEEL_KEY_OK_PIN) )
  2.         {
  3.                 wheel_key_ok = true;
  4.                 exti_interrupt_flag_clear(WHEEL_KEY_OK_EXTI_LINE);
  5.         }
  6.         else {}
  7.         if ((RESET != exti_interrupt_flag_get(WHEEL_KEY_DN_EXTI_LINE)) && !gpio_input_bit_get(WHEEL_KEY_DN_GPIO_PORT, WHEEL_KEY_DN_PIN) )
  8.         {
  9.                 wheel_key_dn = true;
  10.                 exti_interrupt_flag_clear(WHEEL_KEY_DN_EXTI_LINE);
  11.         }
  12.         else {}                                               
  13. }
复制代码



This post is from GD32 MCU

Comments

You can try other external interrupts except external interrupt 0. You can see from my post that exti0 is fine. It's just that other external interrupts are not working. Waiting for your news.  Details Published on 2018-10-1 22:06
 
Personal signature

So TM what......?

 

 

606

Posts

20

Resources
5
 
ljj3166 posted on 2018-10-1 21:43 I have used interrupt sources 0 and 1, but I don't know about the others. Compare the three-way buttons. Only one key value can appear each time
You can try other external interrupts except external interrupt 0. You can see from my post that exti0 is fine. It's just that other external interrupts are not working. Waiting for your news.
This post is from GD32 MCU

Comments

Interrupt source 1 is OK  Details Published on 2018-10-1 22:11
 
 
 

3414

Posts

0

Resources
6
 
ketose posted on 2018-10-1 22:06 You can try other external interrupts except external interrupt 0. You can see my post, exti0 is fine. It's just that other external interrupts...
Interrupt source 1 is fine
This post is from GD32 MCU

Comments

What about other interrupt sources?  Details Published on 2018-10-1 22:16
What about other interrupt sources?  Details Published on 2018-10-1 22:14
 
Personal signature

So TM what......?

 

 

606

Posts

20

Resources
7
 
ljj3166 posted on 2018-10-1 22:11 Interrupt source 1 is fine
What about other interrupt sources?
This post is from GD32 MCU

Comments

B9 tested and available. The original poster's code seems to be missing rcu_periph_clock_enable(RCU_CFGCMP); this  Details Published on 2018-10-1 22:36
 
 
 

606

Posts

20

Resources
8
 
ljj3166 posted on 2018-10-1 22:11 Interrupt source 1 is fine
Where do you think the problem is with my code?
This post is from GD32 MCU
 
 
 

3414

Posts

0

Resources
9
 
ketose posted on 2018-10-1 22:14 What about other sources of interruption?
  1. /* enable the key clock */ rcu_periph_clock_enable(RCU_GPIOB); rcu_periph_clock_enable(RCU_CFGCMP); /* configure button pin as input */ gpio_mode_set(GPIOB, GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN_9); /* enable and set key EXTI interrupt to the lowest priority */ nvic_irq_ enable(EXTI4_15_IRQn, 2U, 0U); /* connect key EXTI line to key GPIO pin */ syscfg_exti_line_config(EXTI_SOURCE_GPIOB, EXTI_SOURCE_PIN9); /* configure key EXTI line */ exti_init(EXTI_9, EXTI_INTERRUPT, EXTI_TRIG_FALLING);
复制代码
B9 tested and available. The original poster's code seems to be missing rcu_periph_clock_enable(RCU_CFGCMP); this
This post is from GD32 MCU

Comments

Of course it’s because of this sentence…  Details Published on 2018-10-2 10:24
 
Personal signature

So TM what......?

 

 

606

Posts

20

Resources
10
 
ljj3166 posted on 2018-10-1 22:36 B9 tested and it works. The original poster's code seems to be missing rcu_periph_clock_enable(RCU_CFGCMP); this thing
It is because of this sentence... Thank you
This post is from GD32 MCU
 
 
 

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