interrupt GPIO->IF_CLR and GPIO->IF logic in the GPIO EFR32FG14

Thread Starter

yef smith

Joined Aug 2, 2020
717
Hello,In the example bellow we define each gpio pin interrupt using
GPIO_ExtIntConfig(BSP_GPIO_PB0_PORT, BSP_GPIO_PB0_PIN,BSP_GPIO_PB0_PIN, 0, 1, true);
BSP_GPIO_PB0_PORT=gpioPortF
BSP_GPIO_PB0_PIN=6
from the signature of thefunction intNo is 6 ,which meand we define our interrupt to be RAC_SEQ_IRQ from the table shown bellow.
then when flag rises we lower the flag by putting GPIO->IF_CLR the value 0xAAAA
0xAAAA=1010101010101010 in binary
but we have defined our interrupt only on port F pin 6 ,why lower flag on so many places?
What it the place in the register for PORT F PIN 6?
Thanks.

1675520544713.png
1675520205230.png


1675520028320.png

Code:
/***************************************************************************//**
 * @file main_s1.c
 * @brief This project demonstrates a using GPIOs to trigger external 
 * interrupts. When PB0 or PB1 is pressed, LED0 or LED1 is toggled, 
 * respectively. See readme.txt for details.
 *******************************************************************************
 * # License
 * <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
 *******************************************************************************
 *
 * SPDX-License-Identifier: Zlib
 *
 * The licensor of this software is Silicon Laboratories Inc.
 *
 * This software is provided 'as-is', without any express or implied
 * warranty. In no event will the authors be held liable for any damages
 * arising from the use of this software.
 *
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:
 *
 * 1. The origin of this software must not be misrepresented; you must not
 *    claim that you wrote the original software. If you use this software
 *    in a product, an acknowledgment in the product documentation would be
 *    appreciated but is not required.
 * 2. Altered source versions must be plainly marked as such, and must not be
 *    misrepresented as being the original software.
 * 3. This notice may not be removed or altered from any source distribution.
 *
 *******************************************************************************
 * # Evaluation Quality
 * This code has been minimally tested to ensure that it builds and is suitable 
 * as a demonstration for evaluation purposes only. This code will be maintained
 * at the sole discretion of Silicon Labs.
 ******************************************************************************/

#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_emu.h"
#include "em_gpio.h"
#include "bsp.h"

/**************************************************************************//**
 * @brief GPIO Even IRQ for pushbuttons on even-numbered pins
 *****************************************************************************/
void GPIO_EVEN_IRQHandler(void) 
{
  // Clear all even pin interrupt flags
    uint32_t res;
    res=GPIO_IntGet();
    GPIO_IntClear(0x5555);

  // Toggle LED0
  GPIO_PinOutToggle(BSP_GPIO_LED0_PORT, BSP_GPIO_LED0_PIN);
}

/**************************************************************************//**
 * @brief GPIO Odd IRQ for pushbuttons on odd-numbered pins
 *****************************************************************************/
void GPIO_ODD_IRQHandler(void) 
{
  // Clear all odd pin interrupt flags
  GPIO_IntClear(0xAAAA);

  // Toggle LED01
  GPIO_PinOutToggle(BSP_GPIO_LED1_PORT, BSP_GPIO_LED1_PIN);
}

/**************************************************************************//**
 * @brief GPIO initialization
 *****************************************************************************/
void initGPIO(void) 
{
  // Enable GPIO clock
  CMU_ClockEnable(cmuClock_GPIO, true);

  // Configure PB0 and PB1 as input with glitch filter enabled
  GPIO_PinModeSet(BSP_GPIO_PB0_PORT, BSP_GPIO_PB0_PIN, gpioModeInputPullFilter, 1);
  GPIO_PinModeSet(BSP_GPIO_PB1_PORT, BSP_GPIO_PB1_PIN, gpioModeInputPullFilter, 1);

  // Configure LED0 and LED1 as output
  GPIO_PinModeSet(BSP_GPIO_LED0_PORT, BSP_GPIO_LED0_PIN, gpioModePushPull, 0);
  GPIO_PinModeSet(BSP_GPIO_LED1_PORT, BSP_GPIO_LED1_PIN, gpioModePushPull, 0);

  // Enable IRQ for even numbered GPIO pins
  NVIC_EnableIRQ(GPIO_EVEN_IRQn);

  // Enable IRQ for odd numbered GPIO pins
  NVIC_EnableIRQ(GPIO_ODD_IRQn);

  // Enable falling-edge interrupts for PB pins
  GPIO_ExtIntConfig(BSP_GPIO_PB0_PORT, BSP_GPIO_PB0_PIN,BSP_GPIO_PB0_PIN, 0, 1, true);
  GPIO_ExtIntConfig(BSP_GPIO_PB1_PORT, BSP_GPIO_PB1_PIN, BSP_GPIO_PB1_PIN, 0, 1, true);
}

/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void) 
{
  // Chip errata
  CHIP_Init();

  // Initializations
  initGPIO();

  while (1){
    // Enter Low Energy Mode until an interrupt occurs
    EMU_EnterEM3(false);
  }
}
 

MrChips

Joined Oct 2, 2009
30,707
You are confusing GPIO port configuration with interrupt vectors.

RAC_SEQ_IRQn is assigned interrupt vector number 6.
This has nothing to do with GPIO pin PF6.
 

Thread Starter

yef smith

Joined Aug 2, 2020
717
Hello MrChips , i know that 6 in interrupt vector number has nothing to do withGPIO PF6,
But why they put 0xAAAA=1010101010101010 in binary into GPIO->IF_CLR (register shown bellow)
inNo parameter is 6 when they defined the interrupt.
Thanks.

1675531585262.png
1675531540407.png
 
Last edited:

Thread Starter

yef smith

Joined Aug 2, 2020
717
Hello MrChips,So if i want to tringger an interrupt on PF 6 i need to spesify intNo from the list bellow.

What is the logic behind choosing a intNo(interrupt number)?

i have a table of interrupt types with a unique number for each. I am using interrupt num 6 in my example ,what will happen if i use interupt number 2? What would change in the system? GPIO_ExtIntConfig(BSP_GPIO_PB0_PORT, BSP_GPIO_PB0_PIN,interrupt_num, 0, 1, true);
Why its important?
Thanks.
GPIO_ExtIntConfig(BSP_GPIO_PB0_PORT, BSP_GPIO_PB0_PIN,jj, 0, 1, true);
1675537377825.png

1675537428528.png
 
Last edited:

MrChips

Joined Oct 2, 2009
30,707
I am not familiar with the Silicon Labs EFR32FG14.

It would appear that all even GPIO pins are vectored to the same interrupt, GPIO_EVEN_IRQn.
All odd GPIO pins are vectored to the same interrupt, GPIO_ODD_IRQn.

Thus if you want to use PF6 to cause an interrupt on GPIO_EVEN_IRQn, you can clear the PF6 interrupt flag by writing 0x0040 to GPIO_IFC register.

Maybe you need to specify the interrupt number as 10.
The description of GPIO_ExtIntConfig( ) is here:

Reference: https://docs.silabs.com/mcu/latest/efr32bg21/group-GPIO


void GPIO_ExtIntConfig(GPIO_Port_TypeDefport,
unsigned intpin,
unsigned intintNo,
boolrisingEdge,
boolfallingEdge,
boolenable
)
Configure the GPIO external pin interrupt.
It is recommended to disable interrupts before configuring the GPIO pin interrupt. See GPIO_IntDisable() for more information.
The GPIO interrupt handler must be in place before enabling the interrupt.
Notice that any pending interrupt for the selected interrupt is cleared by this function.
NoteOn series 0 devices, the pin number parameter is not used. The pin number used on these devices is hardwired to the interrupt with the same number.
On series 1 devices, the pin number can be selected freely within a group. Interrupt numbers are divided into 4 groups (intNo / 4) and valid pin number within the interrupt groups are: 0: pins 0-3 (interrupt number 0-3) 1: pins 4-7 (interrupt number 4-7) 2: pins 8-11 (interrupt number 8-11) 3: pins 12-15 (interrupt number 12-15)Parameters
[in]portThe port to associate with the pin.
[in]pinThe pin number on the port.
[in]intNoThe interrupt number to trigger.
[in]risingEdgeSet to true if the interrupt will be enabled on the rising edge. Otherwise, false.
[in]fallingEdgeSet to true if the interrupt will be enabled on the falling edge. Otherwise, false.
[in]enableSet to true if the interrupt will be enabled after the configuration is complete. False to leave disabled. See GPIO_IntDisable() and GPIO_IntEnable().
Definition at line 182 of file em_gpio.c.
References BUS_RegBitWrite(), BUS_RegMaskedWrite(), and GPIO_IntClear().
Referenced by BOARD_alsEnableIRQ(), BOARD_envSensEnableIRQ(), BOARD_gasSensorEnableIRQ(), BOARD_hallSensorEnableIRQ(), BOARD_imuEnableIRQ(), BOARD_pushButtonEnableIRQ(), and GPIO_IntConfig().
 

Thread Starter

yef smith

Joined Aug 2, 2020
717
Hello MrChips, " It would appear that all even GPIO pins are vectored to same interrupt, GPIO_EVEN_IRQn."
What is the meaning of the words that all even pins are vectored to GPIO_EVEN_IRQn?
What tells you that conclution?
What happen in the system if i use different interrupt number?
Thanks.
 

MrChips

Joined Oct 2, 2009
30,707
From what I can tell, all even GPIO pins, PA0, PA2,...PA14, PB0, PB2, .... PF0, PF2, PF4, PF6... PF14 are sent to GPIO_EVEN_IRQn, number 10. You have to read the interrupt flag to find which pin 0, 2, ..., 14 is triggering the interrupt.

For odd numbered pins, PA1, PA3, etc, use GPIO_ODD_IRQn, number 18.
You cannot use any other interrupt number because they are for different interrupt sources.
 

Thread Starter

yef smith

Joined Aug 2, 2020
717
Hello MrChips, We have two registers regarding flags shown bellow.
So for example GPIO_EVEN_IRQn case its not marking every even pin to one

but if we choose to trigger PF2 then one of the places in IF register will rise.
How do i see which port and which pin in that port has rose by looking at the IF register?
Thanks.
1675553061496.png

1675553230635.png
 

MrChips

Joined Oct 2, 2009
30,707
GPIO_IF (Interrupt Flag) is a 32-bit register, bit-31...bit-0
You are only concerned with the lower 16 bits, bit-15...bit-0.

Event on GPIO pin PF2 will cause GPIO_IF bit-2 to be set, assuming that PF2 interrupt has been enabled and the general interrupt has been enabled.
 

Thread Starter

yef smith

Joined Aug 2, 2020
717
Hello Mr.Chips when our PF7 is triggered i get in the GPIO->IF register a binary '1' in th 7th place(PF7)
then as shown below we put 0x5555 into IF_CLR.
by putting a value inside GPIO->IF_CLR how it make GPIO->IF to be all zeros?
Thanks.

GPIO->IF_CLR = flags;


Code:
void GPIO_EVEN_IRQHandler(void)
{
  // Clear all even pin interrupt flags
    uint32_t res;
    res=GPIO_IntGet();
    GPIO_IntClear(0x5555);

  // Toggle LED0
  GPIO_PinOutToggle(BSP_GPIO_LED0_PORT, BSP_GPIO_LED0_PIN);
}
 
Top