AnsweredAssumed Answered

frdmk28f - multiple GPIO interupt

Question asked by mylim on Feb 21, 2019
Latest reply on Feb 27, 2019 by mylim

Hi, I am new to this. I am trying out to understand the development environment. I am using FRDMK28F board using the gpio_input_interupt example. I manage to load and run the example and pressing SW2 to switch on the RED LED. 

I am trying to figure out for instance with multiple GPIO interupt. for example adding SW3 to switch on/off GREEN LED.

I have tried duplicating the codes and add them as follow but it didn't work. Can anyone advise. Thanks.


#define BOARD_LED_GPIO_SW3 BOARD_LED_GREEN_GPIO
#define BOARD_LED_GPIO_PIN_SW3 BOARD_LED_GREEN_GPIO_PIN

 

#define BOARD_SW_GPIO_SW3 BOARD_SW3_GPIO
#define BOARD_SW_PORT_SW3 BOARD_SW3_PORT
#define BOARD_SW_GPIO_PIN_SW3 BOARD_SW3_GPIO_PIN
#define BOARD_SW_IRQ_SW3 BOARD_SW3_IRQ
#define BOARD_SW_IRQ_HANDLER_SW3 BOARD_SW3_IRQ_HANDLER
#define BOARD_SW_NAME_SW3 BOARD_SW3_NAME


volatile bool g_ButtonPress_SW3 = false;

 

void BOARD_SW_IRQ_HANDLER_SW3(void)
{
GPIO_PortClearInterruptFlags(BOARD_SW_GPIO_SW3, 1U << BOARD_SW_GPIO_PIN_SW3);
g_ButtonPress_SW3 = true;
/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
exception return operation might vector to incorrect interrupt */
#if defined __CORTEX_M && (__CORTEX_M == 4U)
__DSB();
#endif
}

 

#if (defined(FSL_FEATURE_PORT_HAS_NO_INTERRUPT) && FSL_FEATURE_PORT_HAS_NO_INTERRUPT)
GPIO_SetPinInterruptConfig(BOARD_SW_GPIO_SW3, BOARD_SW_GPIO_PIN_SW3, kGPIO_InterruptFallingEdge);
#else
PORT_SetPinInterruptConfig(BOARD_SW_PORT_SW3, BOARD_SW_GPIO_PIN_SW3, kPORT_InterruptFallingEdge);
#endif
EnableIRQ(BOARD_SW_IRQ_SW3);
GPIO_PinInit(BOARD_SW_GPIO_SW3, BOARD_SW_GPIO_PIN_SW3, &sw_config);

 


GPIO_PinInit(BOARD_LED_GPIO_SW3, BOARD_LED_GPIO_PIN_SW3, &led_config);

 

while (1)
{
if (g_ButtonPress)
{
PRINTF(" %s is pressed \r\n", BOARD_SW_NAME);
/* Toggle LED. */
GPIO_PortToggle(BOARD_LED_GPIO, 1U << BOARD_LED_GPIO_PIN);
/* Reset state of button. */
g_ButtonPress = false;
}

if (g_ButtonPress_SW3)
{
PRINTF(" %s is pressed \r\n", BOARD_SW_NAME_SW3);
/* Toggle LED. */
GPIO_PortToggle(BOARD_LED_GPIO_SW3, 1U << BOARD_LED_GPIO_PIN_SW3);
/* Reset state of button. */
g_ButtonPress_SW3 = false;
}
}

gpio isr error

Outcomes