当前位置:网站首页>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);
}
}
边栏推荐
- When you need to use some functions of STM32, but 51 can't realize them, 32 naturally doesn't need to learn
- 顺利毕业[2]-学生健康管理系统 功能开发中。。。
- GPIO port details, Hal library operation keys
- [CSDN]C1训练题解析_第四部分_Web进阶
- Development of fire power monitoring system
- Install local sources using yum
- Project cost management__ Cost management technology__ Article 8 performance review
- MySQL environment variable configuration
- 在三线城市、在县城,很难毕业就拿到10K
- Fundamentals of Electronic Technology (III)__ Fundamentals of circuit analysis__ Basic amplifier operating principle
猜你喜欢

Programming ideas are more important than anything, not more than who can use several functions, but more than the understanding of the program

In third tier cities and counties, it is difficult to get 10K after graduation
![顺利毕业[3]-博客系统 更新中。。。](/img/91/72cdea3eb3f61315595330d2c9016d.png)
顺利毕业[3]-博客系统 更新中。。。

【22毕业季】我是毕业生yo~

Schematic diagram and connection method of six pin self-locking switch

UCI and data multiplexing are transmitted on Pusch (Part VI) -- LDPC coding

When you need to use some functions of STM32, but 51 can't realize them, 32 naturally doesn't need to learn

Shell logic case

Flink learning notes (XI) table API and SQL

Convert IP address to int
随机推荐
Flink learning notes (VIII) multi stream conversion
Raspberry pie installation SciPy
Introduction to chromium embedded framework (CEF)
Chromium Embedded Framework (CEF) 介绍
Matlab reads hexadecimal numbers and converts them into signed short
STM32 serial port usart1 routine
顺利毕业[2]-学生健康管理系统 功能开发中。。。
Nr--- Pusch I: sorting out the agreement process
【顺利毕业】[1]-游览 [学生管理信息系统]
Epoll read / write mode in LT and et modes
MYSQL数据库底层基础专栏
Install local sources using yum
Leetcode daily question (968. binary tree cameras)
Learn the contents of 5g toolbox supporting NR through the NR resources provided by MATLAB
Idea remote breakpoint debugging jar package project
2021-09-26
Project cost management__ Topic of comprehensive calculation
Intelligent home design and development
[CSDN]C1训练题解析_第四部分_Web进阶
STM32 port multiplexing and remapping