= = File exit.h============================================================ #ifndef __exit_h#define__exit_h#include "Stm32f0xx.h" extern void Exit_hall_init (void); #endif/* __exit_h *///== file exit.c==================================== ======================== #include "global.h" #include "exit.h"//======== Hall external interrupt initialization ===========================void Exit_hall_init (void) {gpio_inittypedef gpio_initstruct;//gpio definition exti_inittypedef exti_initstruct;//external interrupt definition NVIC_ Inittypedef nvic_initstruct; Nested interrupt Definitions/* Config the extiline (PB3 PB4 PB5) clock and AFIO clock */Rcc_apb2periphclockcmd (rcc_apb2periph_syscfg, ENA BLE); Rcc_ahbperiphclockcmd (Rcc_ahbperiph_gpiob, ENABLE); /* Configyre p[a| b| c| d| E]3 NIVC */nvic_initstruct.nvic_irqchannel = exti2_3_irqn; nvic_initstruct.nvic_irqchannelpriority = 0x00; Nvic_initstruct.nvic_irqchannelcmd = ENABLE; Nvic_init (&nvic_initstruct); /* Configyre p[a| b| c| d| E]4 5 NIVC */nvic_initstruct.nvic_irqchannel = EXTI4_15_IRQN; Nvic_initstruct.nvic_irqchannelpriority = 0x00; Nvic_initstruct.nvic_irqchannelcmd = ENABLE; Nvic_init (&nvic_initstruct); /* Exti Line gpio config (PB3 PB4 PB5) */gpio_initstruct.gpio_pin = gpio_pin_3| gpio_pin_4| Gpio_pin_5; Gpio_initstruct.gpio_mode = gpio_mode_in; Gpio_initstruct.gpio_speed = gpio_speed_level_2; GPIO_INITSTRUCT.GPIO_PUPD = gpio_pupd_nopull;//gpio_pupd_up; Pull-up input gpio_init (GPIOB, &gpio_initstruct);/* Exti line (PB3 PB4 PB5) mode config */exti_clearitpendingbit (exti_line3 ); Exti_clearitpendingbit (exti_line4); Exti_clearitpendingbit (Exti_line5); Syscfg_extilineconfig (Exti_portsourcegpiob, Exti_pinsource3); Syscfg_extilineconfig (Exti_portsourcegpiob, Exti_pinsource4); Syscfg_extilineconfig (Exti_portsourcegpiob, Exti_pinsource5); Exti_initstruct.exti_line = exti_line3| exti_line4| Exti_line5; Exti_initstruct.exti_mode = Exti_mode_interrupt; Exti_initstruct.exti_trigger = exti_trigger_rising_falling;//exti_trigger_falling;//on falling edge interrupt Exti_initstruct.exti_ Linecmd = ENABLE; Exti_init (&exti_initstruct); }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
stm32f030 IO Port External Interrupt Application