当前位置:网站首页>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);
}
}
边栏推荐
- The cyclic shift of PUCCH in NR channel is generated by MATLAB
- Uniapp realizes global sharing of wechat applet and custom sharing button style
- PRACH --- originator
- Definition and use of enum in C language
- [male nanny style] teach you to open the first wechat applet
- UCI and data multiplexing are transmitted on Pusch - placement of data and UCI positions (Part III)
- Design and development of biological instruments
- Embedded systems are inherently flawed. Compared with the Internet, there are so many holes that it is simply difficult to walk away from
- Leetcode daily question (2305. fair distribution of cookies)
- 內存數據庫究竟是如何發揮內存優勢的?
猜你喜欢

Happy Dragon Boat Festival—— Zongzi written by canvas~~~~~

Getting started with JMX, MBean, mxbean, mbeanserver

Oracle database SQL statement execution plan, statement tracking and optimization instance

应用最广泛的8位单片机当然也是初学者们最容易上手学习的单片机

Development of fire evacuation system
![[CSDN] C1 training problem analysis_ Part II_ Web Foundation](/img/91/72cdea3eb3f61315595330d2c9016d.png)
[CSDN] C1 training problem analysis_ Part II_ Web Foundation

嵌入式本来就很坑,相对于互联网来说那个坑多得简直是难走

Directory and switching operation in file system

Project cost management__ Cost management technology__ Article 6 prediction

Leetcode daily question (2090. K radius subarray averages)
随机推荐
Development of electrical fire system
UCI and data multiplexing are transmitted on Pusch - Part I
UCI and data multiplexing are transmitted on Pusch - determine the bit number of harqack, csi1 and csi2 (Part II)
端午节快乐!—— canvas写的粽子~~~~~
CEF download, compile project
An executable binary file contains more than machine instructions
Leetcode daily question (516. long palindromic subsequence)
Electronic product design, MCU development, circuit cloning
Oracle数据库 SQL语句执行计划、语句跟踪与优化实例
Stm32-hal library learning, using cubemx to generate program framework
SSB Introduction (PbCH and DMRs need to be supplemented)
All processes of top ten management in project management
【力扣刷题笔记(二)】特别技巧,模块突破,45道经典题目分类总结,在不断巩固中精进
Introduction to chromium embedded framework (CEF)
Runtime.getRuntime().gc() 和 Runtime.getRuntime().runFinalization() 的区别
PRACH --- originator
Getting started with shell programming
STM32 external interrupt experiment
Patent inquiry website
Leetcode daily question (1162. as far from land as possible)