STM32F103ZET6 — EXTI

Publisher:dswecdLatest update time:2018-08-14 Source: eefocusKeywords:STM32F103ZET6  EXTI Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

STM32F103ZET6 supports 20 external interrupt inputs (EXIT0~EXIT19), of which there are 4:

EXTI line 16 is connected to the PVD output

EXTI line 17 is connected to the RTC alarm event

EXTI line 18 is connected to the USB wake-up event

EXTI line 19 is connected to Ethernet wake-up event (only for interconnection products)


The other 16 can be used as external input interrupts, including:

EXIT0~EXIT4 have independent interrupt vectors

EXIT6~EXIT9 share an interrupt vector EXTI9_5_IRQHandler

EXIT10~EXIT16 share an interrupt vector EXTI15_10_IRQHandler

The shared interrupt vector needs to read the pending flag in the corresponding ISR to determine which signal triggered the interrupt.


On the board, the PE5/PE6 pins are connected to Key1 and Key2 through pull-up resistors, and the other ends of Key1 and Key2 are connected to GND.

The process of initializing and configuring PE5/PE6 to become an external interrupt is as follows:

1. Enable the clocks of AFIO and GPIO

2. Configure GPIO PE5/PE6 as pull-up input

3. Configure PE5/PE6 as the input pin of external EXIT interrupt through the EXITCR register group of AFIO

4. Configure the EXIT register to enable the interrupt of PE5/PE6

5. Since the level is low after the key is pressed, it is configured to generate an interrupt on the falling edge.

void SK_EXITInit(void)

{

    GPIO_InitTypeDef stGpioInit;

    EXTI_InitTypeDef stEXTIInit;

 

    /// Step 1: Power On the AFIO and GPIOE

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);

 

    /// Step 2: Configure the NVIC

    SK_SK_EXITNVICConfig();

 

    /// Step 3: Config (PE5/PE6) As pull up input

    stGpioInit.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6;

    stGpioInit.GPIO_Mode = GPIO_Mode_IPD;

    GPIO_Init(GPIOE, &stGpioInit);

 

    /// Step 4: Select the output interrupt source

    GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource5);

    GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource6);

 

    /// Step 5: Select the output interrupt source

    stEXTIInit.EXTI_Line = EXTI_Line5 | EXTI_Line6;

    stEXTIInit.EXTI_Mode = EXTI_Mode_Interrupt;

    stEXTIInit.EXTI_Trigger = EXTI_Trigger_Falling;

    stEXTIInit.EXTI_LineCmd = ENABLE;

    EXTI_Init(&stEXTIInit);

}

Since EXIT5~EXIT9 share an interrupt vector, it is necessary to determine the pending flag in the interrupt to know which interrupt line caused the interrupt:


void EXTI9_5_IRQHandler(void)

{

    if(EXTI_GetITStatus(EXTI_Line5) != RESET)

    {

        EXTI_ClearITPendingBit(EXTI_Line5);

        SK_SetLedStatus(SK_LED_1, SK_LED_ON);

        delay_ms(5000);

        SK_SetLedStatus(SK_LED_1, SK_LED_OFF);

    }

 

    if(EXTI_GetITStatus(EXTI_Line6) != RESET)

    {

        EXTI_ClearITPendingBit(EXTI_Line6);

        SK_SetLedStatus(SK_LED_2, SK_LED_ON);

        delay_ms(5000);

        SK_SetLedStatus(SK_LED_2, SK_LED_OFF);

    }

 

}


Keywords:STM32F103ZET6  EXTI Reference address:STM32F103ZET6 — EXTI

Previous article:STM32F103ZET6 — ADC
Next article:STM32F103ZET6 — USART

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号