STM32F030 IO口外部中断应用

Posted lcchuguo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了STM32F030 IO口外部中断应用相关的知识,希望对你有一定的参考价值。

//==文件exit.h============================================================

#ifndef __EXIT_H
#define	__EXIT_H

#include "stm32f0xx.h"

extern void EXIT_HALL_Init(void);

#endif /* __EXIT_H */


//==文件exit.c============================================================


#include "global.h" 
#include "exit.h"

//========霍尔 外部中断 初始化===========================
void EXIT_HALL_Init(void)
{				
		GPIO_InitTypeDef GPIO_InitStruct; //GPIO 定义
  	EXTI_InitTypeDef EXTI_InitStruct; //外部中断定义
	  NVIC_InitTypeDef NVIC_InitStruct; //嵌套中断定义
	  
	  /* config the extiline(PB3 PB4 PB5) clock and AFIO clock */
	  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
	  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; // 上拉输入
		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;//上 下降沿中断
		EXTI_InitStruct.EXTI_LineCmd = ENABLE;
		EXTI_Init(&EXTI_InitStruct); 
				
}








以上是关于STM32F030 IO口外部中断应用的主要内容,如果未能解决你的问题,请参考以下文章

求教stm32f030 HAL库,怎么关闭和打开所有中断

STM32F030如何正确配置IO口的复用功能

STM32F030系列实现仿位带操作

STM32F030系列实现仿位带操作

STM32外部中断EXTI简介

STM32F030 定时器多次溢出才触发中断的问题