Home | Projects | Notes > MCU Peripheral Drivers > Introduction to GPIO

Introduction to GPIO

 

General Purpose Input/Output (GPIO)

 

gpio-basic-structure

 

Input Mode

gpio-input-mode

 

Output Mode

 

gpio-output-mode

 

Alternate Function Mode

 

gpio-alternate-function-mode

 

Summary

 

GPIO Pin Interrupt Configuration

  1. Pin must be in input mode (Because the pin is supposed to be receiving interrupt)

  2. Configure the edge trigger (RT, FR, RFT)

  3. Enable interrupt delivery from the peripheral to the processor (Peripheral side; using Interrupt Mask Register of EXTI)

  4. Identify the IRQ number on which the processor accepts the interrupt from that pin

    • Check the MCU reference manual

  5. Configure the IRQ priority for the identified IRQ number (Process side)

    • Interrupt Priority Registers (NVIC_IPR0 - NVIC_IPRO59)

      Each 32-bit registers are composed of 4 8-bit sections each of which is responsible for each IRQ.

      [!] Tip: IRQ Number / 4 gives IPR number, IRQ Number % 4 gives the section index

  6. Enable interrupt reception on that IRQ number (Processor side; register of NVIC)

    • Interrupt Set-enable Registers (NVIC_ISER0 - NVIC_ISER7) - 0 has no effect, 1 enables the interrupt

    • Interrupt Clear-enable Registers (NVIC_ICER0 - NVIC_ICER7) - 0 has no effect, 1 disables the interrupt

  7. Implement IRQ handler

 

stm32f4-gpio-pins-interrupt-delivery-to-the-processor

Pinx of all GPIO ports will share EXTIx. Then how do you assign a specific port to an EXTIx line? By using the SYSCFG_EXTICR register!

By default, EXTI0 will be used by GPIOA Pin0. Configure SYSCFG_EXTICR to select which GPIO port to use the EXTI line.

 

GPIO Interrupt Handling