Getting started with EXTI

Revision as of 16:04, 26 August 2020 by Registered User
Under construction.png Coming soon

This article explain what is and how to use EXTI through examplesl

1. External interrupt/event controller (EXTI)

The external interrupt/event controller consists of up to 23 edge detectors for generating event/interrupt requests. Each input line can be independently configured to select the type (interrupt or event) and the corresponding trigger event (rising or falling or both).

2. Configure EXTI to turn on LED when user button is pressed

2.1. Objective

  • Learn how to setup input pin with EXTI in STM32CubeMX
  • How to Generate Code in STM32CubeMX and use HAL functions

2.2. Goal

  • Configure GPIO and EXTI pin in STM32CubeMX and Generate Code
  • Add into project Callback function and function which turn on led
  • Verify the correct functionality by pressing button which turns on LED

2.3. Create project in STM32CubeMX

  • Menu > File > New Project
  • Select STM32F439ZITx

File:Select F439.png

  • Configure LED pin as GPIO_Output ( PG14 on NucleoF439ZI, for other board check User Manual)

File:LED UM.png File:LED PIN.png

  • Configure Button pin as GPIO_EXTIX (PA0 on NucleoF439ZI, for other board check User Manual)

File:Button.png

  • GPIO Configuration check
  • Enable the interrupt for EXTI
  • Save your project and generate the code for your IDE

2.4. HAL Library workflow summary

File:EXTI HAL flowchart.png

2.5. Open you IDE

We create function which will handle the EXTI interrupts

  • HAL callback function for EXTI : void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
  • For LED turn on we need to use this functions : HAL_GPIO_WritePin

The functions we want to put into main.c

Info white.png Information
Between /* USER CODE BEGIN 4 */ and /* USER CODE END 4 */ tags
/* USER CODE BEGIN 4 */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  if(GPIO_Pin == GPIO_PIN_0) {
    HAL_GPIO_WritePin(GPIOG, GPIO_PIN_14, GPIO_PIN_SET);
  } else {
      __NOP();
  }
}
/* USER CODE END 4 */

2.6. Compile and flash

  • When you press the blue button of you board the LED should switch on