Reply
Highlighted
Posts: 54
Registered: ‎09-06-2017
Accepted Solution

Determine port on interrupt

When GPIO_ODD_IRQHandler is called on interrupt and I use GPIO_IntGet to get the pending interrupts, this just gives me a pin number, not the port. How can I determine the port in the interrupt handler?

Posts: 54
Registered: ‎09-06-2017

Re: Determine port on interrupt

Also, how do I determine the new input state? Do I need to use 

GPIO_PinInGet?

Posts: 2,326
Registered: ‎10-14-2014

Re: Determine port on interrupt

 @nickb

 

Which part you are using? take the EFM32WG as example, you could see in the reference manual (page 762, section 32.3.5) below sentence:

---------------------

All pins with the same pin number (n) are grouped together to trigger one interrupt flag (EXT[n] in
GPIO_IF).

-----------------

I think this is the reason you could only see the pin number. You should check which port you have configured to fire the interrupt.

 

WeiguoLu
Posts: 54
Registered: ‎09-06-2017

Re: Determine port on interrupt

BGM111.

 

What if you have the interrupt enabled for the same pin on different ports?

Posts: 54
Registered: ‎09-06-2017

Re: Determine port on interrupt

Ah "Only one pin with the same number across all ports can be enabled as an interrupt at any given time.". So I have to make sure I arrange interrupt inputs not to be on the same pin number across different ports. But in theory this still provides up to 16 interrupt pins across all the ports on BGM111.

 

Thanks

Posts: 259
Registered: ‎08-16-2012

Re: Determine port on interrupt

The BGM111 pins within the same group from different ports (e.g. PA0 & PC0) can be selected for the same interrupt source group. Refer to knowledge article below.

http://community.silabs.com/t5/32-bit-MCU-Knowledge-Base/GPIO-interrupt-in-EFM32-Gecko-Series-1-and-...

 

My views are my own and do not necessarily represent the views of Silicon Labs
Posts: 54
Registered: ‎09-06-2017

Re: Determine port on interrupt

Oh ok. AN12 needs updating then, as it does not say that. So I return to my original question, how do I know which port triggered the interrupt?
Posts: 2,326
Registered: ‎10-14-2014

Re: Determine port on interrupt

For one GPIO EXTIx interrupt flag (among the 16) you should configur the port and pin in the firmware to trigger it. when an interrupt happen you could know the port and pin because you configer the combination of port/pin to generate that interrupt.
You could read the GPIO section of the reference manual to know how the GPIO interrupt works.

that is to say, you couldn't use 2 different GPIO to trigger same EXTI[i] interrupt. check register EXTIPSELL/H and EXTIPINSELL/H register in the reference manual.
WeiguoLu
Posts: 54
Registered: ‎09-06-2017

Re: Determine port on interrupt

@delu, I'm pretty sure that directly contradicts what @amenleung just said and the post he just linked to:

"So pins within the same group from different ports (e.g. PA0 & PC0) can be selected for the same interrupt source. The example code below demonstrates how to set up PC6 and PF6 as a GPIO interrupt on EFM32JG/PG."

 

The same pins on different ports on BGM111 can apparently be configured for interrupt at the same time. So my question is how do I determine what port the interrupt occurred on when two pins are configured for interrupt. My guess is that I need to maintain the state of all interrupt pins and check the changes in state when an interrupt occurs but I wanted to know if that was the only way to do this as it is not ideal.

Posts: 2,326
Registered: ‎10-14-2014

Re: Determine port on interrupt

sorry that i may did not make it clear. yes, same pin on different port could generate ddifferent interrupt.
like the code in the KB. PC6 and PF6 are used as interrupt 4 and 6 source.
you could see to diferentiate port/pin that trigger the interrupt the code check the flag GPIO->IFC, if it equals 0x0010(bit 4), then PF4 trigger it.
________________________
/* PF6 as falling edge trigger on GPIO interrupt source 4 */
GPIO_ExtIntConfig(gpioPortF, 6, 4, false, true, true);
________________________
WeiguoLu
Posts: 54
Registered: ‎09-06-2017

Re: Determine port on interrupt

Thanks, that helped me figure it out.

 

I've created the attached code to make GPIO interrupt implementation easier. Usage:

 

#include "gpio_interrupt.h"

int main(void)
{

  /* Initialize peripherals */
  enter_DefaultMode_from_RESET();

  /* Initialize stack */
  gecko_init(&config);

  while (1) {
		/* Event pointer for handling events */
		struct gecko_cmd_packet* evt;

		/* Check for stack event. */
		evt = gecko_wait_event();

		switch (BGLIB_MSG_ID(evt->header)) {
                    case gecko_evt_system_external_signal_id:
			    gecko_evt_system_external_signal(evt->data.evt_system_external_signal.extsignals);
			}
		} break;
	}
}

void gpio_interrupt(GPIO_Port_TypeDef port, int pin, bool state) {
    // full interrupt info provided
}
Posts: 54
Registered: ‎09-06-2017

Re: Determine port on interrupt

Posts: 259
Registered: ‎08-16-2012

Re: Determine port on interrupt

There is also a gpiointerrupt driver in emdrv to handle GPIO interrupt.

C:\SiliconLabs\SimplicityStudio\v4\developer\sdks\gecko_sdk_suite\v1.1\platform\emdrv\gpiointerrupt

My views are my own and do not necessarily represent the views of Silicon Labs
Posts: 54
Registered: ‎09-06-2017

Re: Determine port on interrupt

It would have been nice to know about this from reading the documentation – where is this documented? It's not mentioned in the C guide.

 

This driver has a couple issues though

  • It doesn't support pin to external interrupt mapping/refers to 'pin' instead of 'interrupt number'
  • It doesn't indicate which port the interrupt occurred on/requires a different callback for every interrupt
  • It doesn't dispatch to the main loop

I'm not sure how gecko_external_signal works, can't find the source, my guess is it stores the extsignals value which is checked on the main thread, but presumably it also changes the power state. It would be good to know how to reproduce the functionality without using gecko_external_signal.

Posts: 259
Registered: ‎08-16-2012

Re: Determine port on interrupt

You can find the related documentation under Gecko HAL and Driver API Reference Guide in Simplicity Studio.

Screenshot_1.jpg

The GPIOINT is under EMDRV when the required device is selected. 

Screenshot_2.jpg

My views are my own and do not necessarily represent the views of Silicon Labs