Interrupt does nothing

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Interrupt does nothing

跳至解决方案
983 次查看
javierhernande1
Contributor IV

Hello,

I have this code in order to print a message when the SW3 is pressed but enter in the IF conditional and not print the message and it does not go back into the loop.

I'm using McuExpresso and SDK2.5, the gpios are initialized from pin_mux.c and worsk fine with the numbers and letters in the 7 segment led display, but not the interrupt.

Should I initialize the interrupt also in pin_mux.c, instance of the source file? (as it's in the examples)

/* Init input switch GPIO.*/
#if (defined(FSL_FEATURE_PORT_HAS_NO_INTERRUPT) && FSL_FEATURE_PORT_HAS_NO_INTERRUPT)
 GPIO_SetPinInterruptConfig(BOARD_SW_GPIO, BOARD_SW_GPIO_PIN, kGPIO_InterruptFallingEdge);
#else
 PORT_SetPinInterruptConfig(BOARD_SW_PORT, BOARD_SW_GPIO_PIN, kPORT_InterruptFallingEdge);
#endif
 EnableIRQ(BOARD_SW_IRQ);
 GPIO_PinInit(BOARD_SW_GPIO, BOARD_SW_GPIO_PIN, &sw_config);‍‍‍‍‍‍‍‍

Best regards

标签 (1)
1 解答
821 次查看
nxf51211
NXP Employee
NXP Employee

Hi Javier,

I checked both your main and pinmux files, and I noticed that you don't set SW3 completely. When I tried your code on my side, I saw that you have a function at pinmux.c that you never use called "BOARD_InitButtonsPins" where you can see the configuration for SW3; based on this observation I just added this function inside your main function and with this I was able to call the SW3 interruption without any problem.

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

   /* Init board hardware. */
    BOARD_InitBootPins();

    /**I added your function here!******************************************************/

    BOARD_InitButtonsPins();

    /*********************************************************************************/

    BOARD_InitBootClocks();
    BOARD_InitBootPeripherals();
   /* Init FSL debug console. */
    BOARD_InitDebugConsole();

    PRINTF("Starting program!\n");

/* Init input switch GPIO.*/
#if (defined(FSL_FEATURE_PORT_HAS_NO_INTERRUPT) && FSL_FEATURE_PORT_HAS_NO_INTERRUPT)
 GPIO_SetPinInterruptConfig(BOARD_SW_GPIO, BOARD_SW_GPIO_PIN, kGPIO_InterruptFallingEdge);
#else
 PORT_SetPinInterruptConfig(BOARD_SW_PORT, BOARD_SW_GPIO_PIN, kPORT_InterruptFallingEdge);
#endif
 EnableIRQ(BOARD_SW_IRQ);
 GPIO_PinInit(BOARD_SW_GPIO, BOARD_SW_GPIO_PIN, &sw_config);


 while(1)
 {
  if(g_ButtonPress)
  {
   //for(int i = 0; i<8;i++)
   //{
    PRINTF("button pressed");
    //GPIO_PortToggle((void*)base[i], letter[4][i] << pin[i]);
    //PRINTF("Base %d, Pin %d\n",base[i],pin[i]);
    //delay();
    /* Reset state of button. */
    g_ButtonPress = false;
   //}
   //for (int i=0; i<8; i++){led[i] = number[4][i];}
  }
 }
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I hope this can help you.

Best Regards,

Ricardo Delsordo

在原帖中查看解决方案

2 回复数
822 次查看
nxf51211
NXP Employee
NXP Employee

Hi Javier,

I checked both your main and pinmux files, and I noticed that you don't set SW3 completely. When I tried your code on my side, I saw that you have a function at pinmux.c that you never use called "BOARD_InitButtonsPins" where you can see the configuration for SW3; based on this observation I just added this function inside your main function and with this I was able to call the SW3 interruption without any problem.

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

   /* Init board hardware. */
    BOARD_InitBootPins();

    /**I added your function here!******************************************************/

    BOARD_InitButtonsPins();

    /*********************************************************************************/

    BOARD_InitBootClocks();
    BOARD_InitBootPeripherals();
   /* Init FSL debug console. */
    BOARD_InitDebugConsole();

    PRINTF("Starting program!\n");

/* Init input switch GPIO.*/
#if (defined(FSL_FEATURE_PORT_HAS_NO_INTERRUPT) && FSL_FEATURE_PORT_HAS_NO_INTERRUPT)
 GPIO_SetPinInterruptConfig(BOARD_SW_GPIO, BOARD_SW_GPIO_PIN, kGPIO_InterruptFallingEdge);
#else
 PORT_SetPinInterruptConfig(BOARD_SW_PORT, BOARD_SW_GPIO_PIN, kPORT_InterruptFallingEdge);
#endif
 EnableIRQ(BOARD_SW_IRQ);
 GPIO_PinInit(BOARD_SW_GPIO, BOARD_SW_GPIO_PIN, &sw_config);


 while(1)
 {
  if(g_ButtonPress)
  {
   //for(int i = 0; i<8;i++)
   //{
    PRINTF("button pressed");
    //GPIO_PortToggle((void*)base[i], letter[4][i] << pin[i]);
    //PRINTF("Base %d, Pin %d\n",base[i],pin[i]);
    //delay();
    /* Reset state of button. */
    g_ButtonPress = false;
   //}
   //for (int i=0; i<8; i++){led[i] = number[4][i];}
  }
 }
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I hope this can help you.

Best Regards,

Ricardo Delsordo

821 次查看
javierhernande1
Contributor IV

Thank you, now works fine.

BR

0 项奖励
回复