当前位置:网站首页>Stm32f407 key interrupt
Stm32f407 key interrupt
2022-07-03 09:52:00 【0725 you Guangchuan】
Configure the register through the figure above , Yes 23 External interrupts are shown below
According to external interrupt ,9 System configuration controller (SYSCFG) Chapter of ,SYSCFG external interrupt configuration register 1(SYSCFG_EXTICR1~4) Configure interrupt source and pin ,
See the reference manual for relevant interruptions SYSCFG And interruptions and events 、Core_m4 NVIC Chapter of
1、 Steps to configure key interrupts
(1) To configure PA0 and PC13 Of GPIO Pin type mode
(2) Configure in SYSCFg Interrupt source and pin
(3) Enable the associated clock ,(GPIO and SYSCFG)
(4)/* choice EXTI Interrupt source */
(5) Configure nested vector interrupt controller NVIC
The programming is as follows 、
#include “ygcKeyItr.h”
void ygcNVIC_Configuration()
{
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStruct.NVIC_IRQChannel=EXTI0_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStruct.NVIC_IRQChannelSubPriority=1;
NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStruct);
NVIC_InitStruct.NVIC_IRQChannel=EXTI15_10_IRQn;
NVIC_Init(&NVIC_InitStruct);
}
void ygcEXTI_Key_Config(void)
{
/ Define a GPIO_InitTypeDef Type of structure /
GPIO_InitTypeDef GPIO_InitStructure;
// Can make GPIO The clock
RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOC,ENABLE);
// To configure PA0 and PC13 Input mode pin
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// timing PC13 Pin
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13;
GPIO_Init(GPIOC, &GPIO_InitStructure);
// Can make SYSCFG The clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
/* Connect EXTI Interrupt source To key1 Pin /
SYSCFG_EXTILineConfig( EXTI_PortSourceGPIOA, EXTI_PinSource0);
/ Connect EXTI Interrupt source To key2 Pin */
SYSCFG_EXTILineConfig( EXTI_PortSourceGPIOC, EXTI_PinSource13);
/* Initialize interrupt source */
EXTI_InitTypeDef EXTI_InitStruct;
EXTI_InitStruct.EXTI_Line=EXTI_Line0;// External interrupt channel PA0
EXTI_InitStruct.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger=EXTI_Trigger_Rising;
EXTI_InitStruct.EXTI_LineCmd=ENABLE;
EXTI_Init(&EXTI_InitStruct);
EXTI_InitStruct.EXTI_Line=EXTI_Line13; External interrupt channel PC13
EXTI_Init(&EXTI_InitStruct);
/* The third step : To configure NVIC */
ygcNVIC_Configuration();
/* Configure interrupt function */
}
void EXTI0_IRQHandler(void)//PA0 Interrupt function
{
// Make sure that... Is generated EXTI Line interrupt
if(EXTI_GetITStatus(KEY1_INT_EXTI_LINE) != RESET)
{
// LED1 Take the opposite
LED1_TOGGLE;
// Clears the interrupt flag bit
EXTI_ClearITPendingBit(KEY1_INT_EXTI_LINE);
}
}
void EXTI15_10_IRQHandler(void)//PC13 Interrupt function
{
// Make sure that... Is generated EXTI Line interrupt
if(EXTI_GetITStatus(KEY2_INT_EXTI_LINE) != RESET)
{
// LED2 Take the opposite
LED2_TOGGLE;
// Clears the interrupt flag bit
EXTI_ClearITPendingBit(KEY2_INT_EXTI_LINE);
}
}
边栏推荐
- Leetcode daily question (2109. adding spaces to a string)
- [CSDN] C1 training problem analysis_ Part II_ Web Foundation
- Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 3 --blinker_ MIOT_ Light (lighting technology app control + Xiaoai classmate control)
- CEF download, compile project
- 单片机现在可谓是铺天盖地,种类繁多,让开发者们应接不暇
- Design and development of biological instruments
- Development of fire evacuation system
- Oracle database SQL statement execution plan, statement tracking and optimization instance
- Comment la base de données mémoire joue - t - elle l'avantage de la mémoire?
- Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()
猜你喜欢
新系列单片机还延续了STM32产品家族的低电压和节能两大优势
[male nanny style] teach you to open the first wechat applet
Flink learning notes (IX) status programming
Fundamentals of Electronic Technology (III)_ Integrated operational amplifier and its application__ Basic arithmetic circuit
顺利毕业[2]-学生健康管理系统 功能开发中。。。
单片机职业发展:能做下去的都成牛人了,熬不动就辞职或者改行了
UCI and data multiplexing are transmitted on Pusch (Part 4) --small block lengths
Seven sorting of ten thousand words by hand (code + dynamic diagram demonstration)
[csdn] C1 analyse des questions de formation Partie III Bar _ JS Foundation
嵌入式本来就很坑,相对于互联网来说那个坑多得简直是难走
随机推荐
There is no specific definition of embedded system
Flink CDC practice (including practical steps and screenshots)
单片机职业发展:能做下去的都成牛人了,熬不动就辞职或者改行了
单片机现在可谓是铺天盖地,种类繁多,让开发者们应接不暇
【力扣刷题笔记(二)】特别技巧,模块突破,45道经典题目分类总结,在不断巩固中精进
MySQL 数据库基础知识(系统化一篇入门)
Project cost management__ Cost management technology__ Article 7 completion performance index (tcpi)
Project cost management__ Topic of comprehensive calculation
NR technology -- MIMO
Embedded systems are inherently flawed. Compared with the Internet, there are so many holes that it is simply difficult to walk away from
Fundamentals of Electronic Technology (III)__ Logic gate symbols in Chapter 5
MySQL data manipulation language DML common commands
我想各位朋友都应该知道学习的基本规律就是:从易到难
Code word in NR
Nodemcu-esp8266 development board to build Arduino ide development environment
Implementing distributed lock with redis
Flink learning notes (XI) table API and SQL
要选择那种语言为单片机编写程序呢
Project cost management__ Plan value_ Earned value_ Relationship among actual cost and Countermeasures
UCI and data multiplexing are transmitted on Pusch (Part 4) --small block lengths