External input interrupt application [EXTI for STM32]

This is an example of an interrupt application with an external input signal. The following is an explanation of the unique part of external interrupts.

This is an application of the EXTI external interrupt for the STM32 MCU. This is an example of an application in which a pushbutton switch is used as an interrupt input to switch the output LED on and off. Interrupt inputs are sensitive, so care must be taken to prevent chattering when using them.

Setting Spec.:
Input  PC13 Floating input 
OutputPA5 Push-pull output+500Ω+LED

External interrupt input

The sample program Exti.c switches the flag interrupt_flag state each time an interrupt by pushbutton SW input is received, and turns on or off the output LED according to the state.

Set the NVIC settings for using interrupts, specifying the priority and the interrupt channel to be used; for interrupts from PC13 input, specify EXTI5_10_IRQn (EXTI line [I5:10] interrupt) as the interrupt channel.

Interrupt input is sensitive and chattering occurs in the pushbutton SW, so the next interrupt is not accepted for 1000 ms after an interrupt input. The cycle time of the infinite program loop is counted for 1000 ms as 1 ms by the delay_ms function.

In the interrupt handle, the external interrupt that occurred is determined to be due to pin 13 with EXTI_GetITStatus(EXTI_Line13).

The point

When using external interrupts, the clock must be supplied to AFIO in addition to GPIO.

Follow me!