i.mx8mq m4 GPIO interrupt setting

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

i.mx8mq m4 GPIO interrupt setting

952 Views
jfglkaer
Contributor I

將GPIO2_PIN20腳位設成輸入中斷GPIO,可以偵測到輸入腳位的狀態,但是狀態有改變,也不能進入中斷,不知道程式那邊沒有設定好或是中斷函式用錯。

#define EXAMPLE_LED_GPIO GPIO2
#define EXAMPLE_LED_GPIO_PIN 20U
#define EXAMPLE_DELAY_COUNT 400000U

/*******************************************************************************
 * Prototypes
 ******************************************************************************/
/*!
 * @brief delay a while.
 */
void delay(void);

/*******************************************************************************
 * Variables
 ******************************************************************************/
/* The PIN status */
volatile bool g_pinSet = false;
/*******************************************************************************
 * Code
 ******************************************************************************/
void delay(void)
{
    volatile uint32_t i = 0;
    for (i = 0; i < EXAMPLE_DELAY_COUNT; ++i)
    {
        __asm("NOP"); /* delay */
    }
}

void GPIO2_Combined_16_31_IRQHandler()
{
  PRINTF("\r\n Interrupt\r\n");
}

/*!
 * @brief Main function
 */
int main(void)
{
    gpio_pin_config_t led_config = {kGPIO_DigitalInput, 1, kGPIO_IntRisingEdge};
    BOARD_RdcInit();

    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitDebugConsole();
    BOARD_InitMemory();
    PRINTF("\r\n GPIO Driver example\r\n");
    PRINTF("\r\n The LED is blinking.\r\n");

    /* Init output LED GPIO. */
    GPIO_PinInit(EXAMPLE_LED_GPIO, EXAMPLE_LED_GPIO_PIN, &led_config);
    GPIO_PinSetInterruptConfig(EXAMPLE_LED_GPIO, EXAMPLE_LED_GPIO_PIN, kGPIO_IntRisingEdge);
    GPIO_PortEnableInterrupts(EXAMPLE_LED_GPIO, 1u << EXAMPLE_LED_GPIO_PIN);
   
    while (1)
    {
       if(GPIO_ReadPinInput(EXAMPLE_LED_GPIO, EXAMPLE_LED_GPIO_PIN)== 1)
       {
         PRINTF("\r\n The LED is 1.\r\n");
       }
       else
       {
         PRINTF("\r\n The LED is 0.\r\n");
       }
       delay();

    }

}

0 Kudos
1 Reply

831 Views
weidong_sun
NXP TechSupport
NXP TechSupport

See the link, please!

https://community.nxp.com/thread/521319 

Have a nice day!

BR,

Weidong

0 Kudos