Proteus emulates EXTI of STM32F103R6 microcontroller

The external interrupt/event controller (External Interrupt/Event Controller, EXTI) of the STM32 microcontroller manages the interrupt/event line of the controller. Each interrupt/event line corresponds to an edge detector, which can detect the rising edge and falling edge of the input signal. EXTI can realize the individual configuration of each interrupt/event line, which can be individually configured as an interrupt or event, and the attributes of the trigger event.

One, add interrupt service routine

void EXTI0_IRQHandler(void)
{
	if(EXTI_GetITStatus(EXTI_Line0) != RESET)
	{
		// Toggle LED
		GPIOB->ODR ^= GPIO_Pin_All;
		
		// Clear the  EXTI line 0 pending bit
		EXTI_ClearITPendingBit(EXTI_Line0);
	}
}

Two, configure EXTI

void EXTI0_Config(void)
{
    EXTI_InitTypeDef EXTI_InitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;
    NVIC_InitTypeDef NVIC_InitStructure;
     
    // Enable GPIOC clock
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
     
    // Configure PC.00 pin as input floating
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
     
    // Enable AFIO clock
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
     
    // Connect EXTI0 Line to PC.00 pin
    GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource0);
     
    // Configure EXTI0 line
    EXTI_InitStructure.EXTI_Line = EXTI_Line0;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&EXTI_InitStructure);
     
    // Enable and set EXTI0 Interrupt to the lowest priority
    NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
}

 

Guess you like

Origin blog.csdn.net/ctrigger/article/details/112979291