AnsweredAssumed Answered

Freedom KL27 external GPIO Interrupt

Question asked by asdasd asdawd on Oct 11, 2017

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"
/*******************************************************************************
* Definitions
******************************************************************************/

#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

/*******************************************************************************
* Prototypes
******************************************************************************/


/*******************************************************************************
* Variables
******************************************************************************/

/* Whether the SW button is pressed */
volatile bool g_ButtonPress = false;

/*******************************************************************************
* Code
******************************************************************************/

/*!
* @brief Interrupt service fuction of switch.
*
* This function toggles the LED
*/

void BOARD_SW_IRQ_HANDLER(void)
{
    /* Clear external interrupt flag. */
    GPIO_ClearPinsInterruptFlags(BOARD_SW_GPIO, 1U << BOARD_SW_GPIO_PIN);
    /* Change state of button. */
    g_ButtonPress = true;
    PRINTF("\r\n Interrupt Occurred\r\n");
    /* Toggle LED. */
    GPIO_TogglePinsOutput(BOARD_LED_GPIO, 1U << BOARD_LED_GPIO_PIN);
}

/*!
* @brief Main function
*/

int main(void)
{
    /* Define the init structure for the input switch pin */
    gpio_pin_config_t sw_config = {
        kGPIO_DigitalInput, 0,
    };

    /* Define the init structure for the output LED pin */
    gpio_pin_config_t led_config = {
        kGPIO_DigitalOutput, 0,
    };

    BOARD_InitPins();
    BOARD_BootClockRUN(); //Changed from BOARD_BootClockHSRUN();
    BOARD_InitDebugConsole();

    CLOCK_EnableClock(kCLOCK_PortA);
    CLOCK_EnableClock(kCLOCK_PortB);
    CLOCK_EnableClock(kCLOCK_PortC);

    /* Print a note to terminal. */
    PRINTF("\r\n GPIO Driver example\r\n");
    PRINTF("\r\n Press %s to turn on/off a LED \r\n", BOARD_SW_NAME);

    /* Init input switch GPIO. */
    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);

    /* Init output LED GPIO. */
    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);
            /* Reset state of button. */
            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

Outcomes