1. Enable peripheral clock
Turn on the clock for the GPIO port (and interrupt controller, if separately gated).
2. Select and Configure the pin as input
Select the pin for which falling edge interrupt can be configured. Set the target pin's mode register to input mode.
3. Configure pull resistor (optional but common)
If the signal floats when idle, enable an internal pull-up or pull-down so the pin has a defined "high" resting state before the falling edge occurs. If your board has on-board pull-up, you can ignore this.
4. Select edge-trigger type
In the interrupt/EXTI configuration register, set the trigger for that pin to falling edge (as opposed to rising, both, or level-triggered).
5. Map the pin to an interrupt line
On some MCUs (e.g., STM32 EXTI), you must explicitly connect the GPIO pin to its corresponding external interrupt line/channel.
6. Enable the interrupt at the peripheral level
Unmask the interrupt for that specific pin/line in the interrupt mask register.
7. Enable the interrupt in the NVIC / global interrupt controller
Enable the corresponding IRQ in the CPU's interrupt controller and set a priority level.
8. Enable global interrupts
Make sure the CPU's global interrupt enable flag is set (often done once at startup).
9. Write the ISR (Interrupt Service Routine)
- Check/clear the interrupt pending flag first (many MCUs require this, or the ISR will re-trigger immediately).
- Keep the ISR short — do minimal work (e.g., set a flag, read a value) and defer heavy processing to the main loop.
10. Test with debounce consideration
Mechanical switches bounce; add a debounce (hardware RC filter or software timer check) if the falling edge comes from a button rather than a clean digital signal.