stm32f4有7個外部gpio中斷源,它們負責分配給每個組的gpio[15..0];
對應關係為
外部中斷初始化順序為:
gpio_inittypedef gpio_initstructure;
nvic_inittypedef nvic_initstructure;
exti_inittypedef exti_initstructure;
(rcc->ahb1enr) |= rcc_ahb1enr_gpioeen;//gpio clk enable
rcc_apb2periphclockcmd(rcc_apb2periph_syscfg, enable);//使能syscfg時鐘
gpio_initstructure.gpio_pin = gpio_pin_4 | gpio_pin_5;
gpio_initstructure.gpio_mode = gpio_mode_in;
gpio_initstructure.gpio_speed = gpio_fast_speed;
gpio_initstructure.gpio_pupd = gpio_pupd_nopull;
gpio_init(gpioe, &gpio_initstructure);
syscfg_extilineconfig(exti_portsourcegpioe,exti_pinsource4);
syscfg_extilineconfig(exti_portsourcegpioe,exti_pinsource5);
exti_initstructure.exti_line = exti_line4 | exti_line5;
exti_initstructure.exti_mode = exti_mode_interrupt;
exti_initstructure.exti_trigger = exti_trigger_rising;
exti_initstructure.exti_linecmd = enable;
exti_init(&exti_initstructure);
nvic_initstructure.nvic_irqchannel = exti4_irqn;
nvic_initstructure.nvic_irqchannelpreemptionpriority= 0x01;
nvic_initstructure.nvic_irqchannelsubpriority = 0x02;
nvic_initstructure.nvic_irqchannelcmd = enable;
nvic_init(&nvic_initstructure);
nvic_initstructure.nvic_irqchannel = exti9_5_irqn;
nvic_initstructure.nvic_irqchannelpreemptionpriority= 0x00;
nvic_initstructure.nvic_irqchannelsubpriority = 0x02;
nvic_initstructure.nvic_irqchannelcmd = enable;
nvic_init(&nvic_initstructure);
使能syscfg時鐘及io口時鐘
初始化io口為輸入
設定io口與中斷線的對映關係
初始化線上中斷,設定觸發條件
配置中斷分組(nvic)並使能中斷
編寫中斷服務函式(清除中斷標誌位)
執行結果:
(全文完)
STM32F4外部中斷設定
c void mpuintinit void void mpu exit it handler h define mpu exit gpio gpioa define mpu exit gpio pin gpio pin 1 define mpu exit rccperiph rcc ahb1per...
STM32F4之GPIO的使用
上次學stm32f103是在大二的暑假,學了一段時間之後也沒有專案做,漸漸地就轉向其他的方向,最近實習要用到stm32f407,就打算從頭學,但是一些基礎還在,並決定將學習的過程記錄一下,以備使用。一.stm32f407zgt6的gpio資源介紹 stm32f407zgt6 一共有7組io口 每組i...
STM32F4中斷總結
使能syscfg時鐘 只要我們使用到外部中斷,就必須開啟syscfg時鐘,因為要用到相關暫存器如配置gpio與中斷線的對映關係 apb2上 設定io口與中斷線的對映關係,syscfg extilineconfig 初始化線上中斷,設定觸發條件等,exti init 配置中斷分組 nvic 並使能中斷...