Hello.
I have a FRDM-K27Z board and want to use a external GPIO Interrupt on PTC3. For testing the GPIO Interrupt i use the Switch 3 on the PTC1. I have the problem, that the Interrupt is never called. I used the example of the KSDK 2.0 and made minimal changes but the Interrupt Function is never called.
Below you can see the code i used. Maybe you can find some errors in that code or help me otherwise.
#include "fsl_debug_console.h"
#include "fsl_port.h"
#include "fsl_gpio.h"
#include "fsl_common.h"
#include "board.h"
#include "pin_mux.h"
#include "fsl_device_registers.h"
#include <stdbool.h>
#include "clock_config.h"
#define BOARD_LED_GPIO BOARD_LED_RED_GPIO
#define BOARD_LED_GPIO_PIN BOARD_LED_RED_GPIO_PIN
#define BOARD_SW_GPIO BOARD_SW3_GPIO
#define BOARD_SW_PORT BOARD_SW3_PORT
#define BOARD_SW_GPIO_PIN BOARD_SW3_GPIO_PIN
#define BOARD_SW_IRQ BOARD_SW3_IRQ
#define BOARD_SW_IRQ_HANDLER BOARD_SW3_IRQ_HANDLER
#define BOARD_SW_NAME BOARD_SW3_NAME
volatile bool g_ButtonPress = false;
void BOARD_SW_IRQ_HANDLER(void)
{
GPIO_ClearPinsInterruptFlags(BOARD_SW_GPIO, 1U << BOARD_SW_GPIO_PIN);
g_ButtonPress = true;
PRINTF("\r\n Interrupt Occurred\r\n");
GPIO_TogglePinsOutput(BOARD_LED_GPIO, 1U << BOARD_LED_GPIO_PIN);
}
int main(void)
{
gpio_pin_config_t sw_config = {
kGPIO_DigitalInput, 0,
};
gpio_pin_config_t led_config = {
kGPIO_DigitalOutput, 0,
};
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
CLOCK_EnableClock(kCLOCK_PortA);
CLOCK_EnableClock(kCLOCK_PortB);
CLOCK_EnableClock(kCLOCK_PortC);
PRINTF("\r\n GPIO Driver example\r\n");
PRINTF("\r\n Press %s to turn on/off a LED \r\n", BOARD_SW_NAME);
PORT_SetPinInterruptConfig(BOARD_SW_PORT, BOARD_SW_GPIO_PIN, kPORT_InterruptFallingEdge);
EnableIRQ(BOARD_SW_IRQ);
GPIO_PinInit(BOARD_SW_GPIO, BOARD_SW_GPIO_PIN, &sw_config);
GPIO_PinInit(BOARD_LED_GPIO, BOARD_LED_GPIO_PIN, &led_config);
while (1)
{
if (g_ButtonPress)
{
PRINTF(" %s is pressed \r\n", BOARD_SW_NAME);
g_ButtonPress = false;
}
}
}
Killerawft
Edit: I also tested the SW3 itself and the switch worked fine without an Interrupt so the error must be in my code.
Edit 2: i tested the same Code as above with the SW1 and the line
PORT_SetPinMux(BOARD_SW_PORT, BOARD_SW_GPIO_PIN, kPORT_MuxAsGpio);
after line 80 and that worked. So I can call the Interrupt of the Port A with my Code, but i need to Call an Interrupt with the Port C GPIO.
Original Attachment has been moved to: gpio_interrupt.elf.zip