stm32--External interrupt Exit implementation

Source: Internet
Author: User

External interrupt Implementation steps:

First, initialization, including: 1. Afio clock Interrupt and Gpio clock enable;

2.GPIO initialization

3. Set the Exti line

4. Interrupt Vector Initialization

Second, interrupt service function

Using PB9 as an external interrupt source, the implementation program is as follows:

First, initialize

1 voidExti_pb9_init (void)2 3 {4 5 gpio_inittypedef gpio_initstructure;6 7 nvic_inittypedef nvic_initstructure;8 9 exti_inittypedef exti_initstructure;Ten  One     //1. Enable Gpio and Afio clocks, it is worth noting that when using an external interrupt must be enabled AFIO clock.  A  -Rcc_apb2periphclockcmd (rcc_apb2periph_gpiob|rcc_apb2periph_afio,enable); -  the     //2.GPIO Initialization -  -Gpio_initstructure.gpio_pin =Gpio_pin_9; -  +Gpio_initstructure.gpio_mode = gpio_mode_in_floating;//Floating Air Input -  +Gpio_initstructure.gpio_speed = Gpio_speed_50mhz;//io speed is 50MHz A  atGpio_init (gpiob,&gpio_initstructure);  -  -     //3. Set the Exti line -  -Gpio_extilineconfig (GPIO_PORTSOURCEGPIOB,GPIO_PINSOURCE9);//Connect exit Line 9 to PB9 -  inExti_initstructure.exti_line =Exti_line9; -  toExti_initstructure.exti_mode =Exti_mode_interrupt; +  -Exti_initstructure.exti_trigger = exti_trigger_rising_falling;//rising falling edge trigger the  *Exti_initstructure.exti_linecmd = ENABLE;//Enable interrupt line $ Panax NotoginsengExti_init (&exti_initstructure);//Initializing interrupts -  the     //4. Interrupt Vector +  ANvic_initstructure.nvic_irqchannel =exti9_5_irqn; the  +Nvic_initstructure.nvic_irqchannelpreemptionpriority =0; -  $Nvic_initstructure.nvic_irqchannelsubpriority =3; $  -Nvic_initstructure.nvic_irqchannelcmd =ENABLE; -  theNvic_init (&nvic_initstructure); - Wuyi}

Second, interrupt service function

1 voidExti9_5_irqhandler (void)2 3 {4 5     if(Exti_getitstatus (exti_line9)! = RESET)//EXTI9 generated an interrupt.6 7 {8 9。。。。。。。。。。//interrupt processing, self-brain repair ~ ~ ~Ten  One } A  -Exti_clearitpendingbit (EXTI_LINE9);//Clear Interrupts -  the}

Attention:

1. External interrupt 5~ External Interrupt 9 is the use of the same interrupt function Exti9_5_irqhandler, if you want to use simultaneously, you need to distinguish between broken in the interrupt function, such as:

if (Exti_getitstatus (exti_line9)! = RESET)//exti9 generates an interrupt
2. The external interrupt line and PIN number are one by one corresponding, such as:
Exti1--> Pin1;
Exti2--> Pin2;
Exti3--> Pin3;
Exti4--> Pin4;
。。。
Instead of randomly mapped.

stm32--External interrupt Exit implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.