STM32F429 external interrupt

Publisher:导航灯Latest update time:2018-12-26 Source: eefocusKeywords:STM32F429 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

7 interrupt channels are used in NVRC


7 interrupt service functions EXPORT EXTI9_5_IRQHandler      


22 interrupt lines


The interrupt source is any GPIO you want to connect, use that to connect SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);


Configure NVRC—Configure GPIO (turn on SYSCFG clock)—Connect interrupt source to GPIO—Configure interrupt EXTI—Write interrupt service function


details as follows


Each IO of STM32F4 can be used as an interrupt input port for external interrupts, which is also the strength of STM32F4. The interrupt controller of STM32F407 supports 22 external interrupt/event requests. Each interrupt has a status bit, and each interrupt/event has independent trigger and mask settings. The 22 external interrupts of STM32F407 are:


EXTI lines 0~15: correspond to input interrupts of external IO ports.


EXTI line 16: Connect to PVD output.


EXTI line 17: connected to the RTC alarm event.


EXTI line 18: connected to USB OTG FS wake-up event.


EXTI line 19: Connected to Ethernet wake-up event.


EXTI line 20: connected to USB OTG HS (configured in FS) wake-up event.


EXTI line 21: Connected to RTC intrusion and timestamp events.


EXTI line 22: connected to RTC wake-up event.




Mapping diagram of GPIO and interrupt lines:




Steps for library function to configure external interrupts:


1) Enable the IO port clock and initialize the IO port as input


    GPIO_InitTypeDef GPIO_InitStructure; 



RCC_AHB1PeriphClockCmd(KEY1_INT_GPIO_CLK|KEY2_INT_GPIO_CLK ,ENABLE);


  GPIO_InitStructure.GPIO_Pin = KEY1_INT_GPIO_PIN;

 

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;                


  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;


  GPIO_Init(KEY1_INT_GPIO_PORT, &GPIO_InitStructure); 



2) Turn on the SYSCFG clock and set the mapping relationship between the IO port and the interrupt line.


/*SYSCFG clock must be enabled when using GPIO external interrupt*/


  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);


Configure the mapping relationship between GPIO and interrupt lines (connect interrupt sources to GPIO pins)


SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);


Mapping interrupt line 0 to GPIOA, it is obvious that GPIOA.0 is connected to the EXTI0 interrupt line.


3) Initialize online interrupts, set trigger conditions, etc.


EXTI_InitTypeDef EXTI_InitStructure;


EXTI_InitStructure.EXTI_Line=EXTI_Line4; (电影手机源)(EXTI_Line0~EXTI_Line15)


EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; (interrupt mode) (divided into interrupt and event)


EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; (Falling edge trigger) (Rising edge triggers Rising, any level triggers Rising_Fallingr)


EXTI_InitStructure.EXTI_LineCmd = ENABLE;


 EXTI_Init(&EXTI_InitStructure); //Initialize the peripheral EXTI register


The above example sets the interrupt on interrupt line 4 to be falling edge triggered.

4) Configure the interrupt group (NVIC) and enable interrupts.


Set the interrupt priority of interrupt line 2. In the WildFire routine, set NVRC to a function static void NVIC_Configuration(void) called in void EXTI_Key_Config(void).


NVIC_InitTypeDef  NVIC_InitStructure;


NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn; // Enable the external interrupt channel of the key. Interrupt lines 0-4 each correspond to one channel, interrupt lines 5-9 share EXTI9_5_IRQ, and interrupt lines 10-15 share EXTI15_10_IRQ


NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02; //Preemption priority 2,


NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x02; //Response priority 2


NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //Enable external interrupt channel


NVIC_Init(&NVIC_InitStructure); //Interrupt priority group initialization


5) Write the interrupt service function.


The names of the interrupt service functions are pre-defined in MDK. It should be noted here that the STM32F4 IO port has only 7 external interrupt functions, namely:

EXPORT  EXTI0_IRQHandler         


EXPORT  EXTI1_IRQHandler      


EXPORT  EXTI2_IRQHandler        


EXPORT  EXTI3_IRQHandler       


EXPORT  EXTI4_IRQHandler          


EXPORT  EXTI9_5_IRQHandler       


EXPORT  EXTI15_10_IRQHandler     


Each interrupt line 0-4 corresponds to an interrupt function, interrupt lines 5-9 share the interrupt function EXTI9_5_IRQHandler, and interrupt lines 10-15 share the interrupt function EXTI15_10_IRQHandler.


The commonly used interrupt service function format is:


void EXTI3_IRQHandler(void)


{


if(EXTI_GetITStatus(EXTI_Line3)!=RESET)//Judge whether an interruption on a line occurs    


       { ...interrupt logic...


        EXTI_ClearITPendingBit(EXTI_Line3); //Clear the interrupt flag on LINE 


       }           


}


Summarize the general steps of using IO port external interrupts:

1) Enable the IO port clock and initialize the IO port as input.


2) Enable the SYSCFG clock and set the mapping relationship between the IO port and the interrupt line.


3) Initialize online interrupts, set trigger conditions, etc.


4) Configure the interrupt group (NVIC) and enable interrupts.


5) Write the interrupt service function.


The simple routine is as follows


#include "stm32f4xx.h"

#include "stm32f4xx_exti.h"

#include "stm32f4xx_rcc.h"

#include "stm32f4xx_gpio.h"

#include "stm32f4xx_syscfg.h"

 

void main(void)

{

config(); // Initialization

while(1);

 

}

 

 

 

void config(void)

{

   //Interrupt IO port initialization

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);   //

RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

//GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_Init(GPIOD, &GPIO_InitStructure);  

 

//Interrupt initialization

EXTI_InitTypeDef EXTI_InitStructure;

 

SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOD, EXTI_PinSource13);

EXTI_ClearITPendingBit(EXTI_Line13);

EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;

EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;

EXTI_InitStructure.EXTI_Line = EXTI_Line13;

EXTI_InitStructure.EXTI_LineCmd = ENABLE;

EXTI_Init(&EXTI_InitStructure);

 

//Interrupt configuration initialization

/* Configures the nested vectored interrupt controller. */

NVIC_InitTypeDef NVIC_InitStructure;

 

/* Enable the USARTx Interrupt */

NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);


}

 

 

 

//Interrupt function

void EXTI15_10_IRQHandler(void)

{


if ( EXTI_GetITStatus(EXTI_Line13) != RESET )

{

EXTI_ClearITPendingBit(EXTI_Line13);//清电影

}

}

Keywords:STM32F429 Reference address:STM32F429 external interrupt

Previous article:STM32F4XX interrupt number definition
Next article:A collection of problems encountered during the use of STM

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号