STM32 Study Notes: EXTI (external interruption)

Source: Internet
Author: User

References: STM32 Data Manual and network Materials

========================================================== = Split line ============================================ ===

The external interrupt/event controller consists of 19 edge detectors that generate event/interrupt requirements. Each input line can be configured independently.

The input type (pulse or suspension) and the corresponding trigger event (both the rising or falling edges and the bilateral edges are triggered ). Each input line can be unique

. The pending register maintains the interrupt requirements of the Status line.

========================================================== = Split line ============================================ ===

19 interruptions are as follows:

Connect the 17--EXTI line 16 to the PCIe output

The 18--EXTI line 17 is connected to the RTC alarm event.

19--EXTI wire 18 connection to USB wake-up event

Note: we can see that the EXTI0 connection pins are PA0, PB0, PC0, PD0, PE0, PF0, PG0, and other external interruptions EXTI1 --

EXTI15 is similar. Therefore, try to configure the required external interrupt on different EXTIx during use.

For example, if three external interrupts are required, we can configure them to PA0, PB4, and pg3. at this time, each interrupt has its own interrupt processing process.

Segment. If PA0, PB0, or PC1 is configured, PA0 and PB0 share an interrupt segment. If you have special requirements

It can be designed in this way.

========================================================== = Split line ============================================ ===

Configuration and usage:

Initialize the corresponding GPIO pin, configure the external interrupt source, and connect the interrupt source and GPIO to write the interrupt processing program for the corresponding interrupt source.

========================================================== = Split line ============================================ ===

Program code

Initialize the corresponding GPIO pin

GPIO_InitTypeDef GPIO_InitStructure;


RCC_APB2PeriphClockCmd (RCC_APB2Periph_AFIO, ENABLE );
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOE, ENABLE );
RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOB, ENABLE );


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init (GPIOE, & GPIO_InitStructure );


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init (GPIOB, & GPIO_InitStructure );

Note: The GPIO reuse function must be enabled, such as the red part.

Configure the external interrupt source and connect the interrupt source and GPIO


GPIO_EXTILineConfig (GPIO_PortSourceGPIOE, GPIO_PinSource0 );
GPIO_EXTILineConfig (GPIO_PortSourceGPIOE, GPIO_PinSource1 );
GPIO_EXTILineConfig (GPIO_PortSourceGPIOB, GPIO_PinSource8 );
GPIO_EXTILineConfig (GPIO_PortSourceGPIOB, GPIO_PinSource9 );


EXTI_InitStructure.EXTI_Line = EXTI_Line0 | EXTI_Line1 | EXTI_Line8 | EXTI_Line9;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init (& EXTI_InitStructure );

Compile the interrupt processing program for the corresponding interrupt source


Void EXTI0_IRQHandler (void)
{
If (Sys_Status> MIN_STATUS)
{
Sys_Status --;
}
EXTI_ClearITPendingBit (EXTI_Line0 );
}


Void EXTI1_IRQHandler (void)
{
PEout (2) = ~ PEout (2 );
EXTI_ClearITPendingBit (EXTI_Line1 );
}


# Define Exti_From_Pin8 0x00000100
# Define Exti_From_Pin9 0x00000200

Void EXTI9_5_IRQHandler (void)
{

U32 Temp = 0x00;

PEout (2) = ~ PEout (2 );
Temp = EXTI-> PR; // read is the interruption of that pin
Switch (Temp)
{
CaseExti_From_Pin8:
EXTI_ClearITPendingBit (EXTI_Line8 );
Break;
CaseExti_From_Pin9:
If (Sys_Status <MAX_STATUS)
{
Sys_Status ++;
}
EXTI_ClearITPendingBit (EXTI_Line9 );
Break;
Default: break;
}
}

========================================================== = Split line ============================================ ===

Interrupt handler description, because the external interrupt EXTI5--EXTI9 shares an interrupt (similar to the EXTI10--EXTI15 ),

Different interrupt sources need to be differentiated. In the above EXTI9_5_IRQHandler, read the EXTI-> PR register to determine

The source of the disconnection.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.