AnsweredAssumed Answered

External interrupts on KBI pins of MKE04Z

Question asked by Shoaib Shaikh on Oct 9, 2018
Latest reply on Oct 11, 2018 by Robin_Shen

Hello everyone,

I am not able to use the KBI pins available on MKE04Z128VLK4 as external interrupts. Only one pin at a time is working but if I try to use two of them together, the interrupt does not occur.

 

#define EXAMPLE_KBI KBI1
#define EXAMPLE_KBI_PIN1 30
#define EXAMPLE_KBI_PIN2 31

 

volatile bool g_keypress = false;

 

void delay(void)
{
    volatile uint32_t i = 0;
    for (i = 0; i < 800000; ++i)
    {
        __asm("NOP"); // delay
    }
}

 

void KBI1_IRQHandler(void)
{
    if (KBI_IsInterruptRequestDetected(EXAMPLE_KBI))
    {
        /* Disable interrupts. */
        KBI_DisableInterrupts(EXAMPLE_KBI);
        /* Clear status. */

 

        KBI_ClearInterruptFlag(EXAMPLE_KBI);

 

        g_keypress = true;

 

        KBI_EnableInterrupts(EXAMPLE_KBI);
    }
/* 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
}


int main(void) {
      /* Init board hardware. */
    BOARD_InitBootPins();
    BOARD_InitBootClocks();
    BOARD_InitBootPeripherals();

 

    kbi_config_t kbiConfig;

 


    PORT_SetFilterSelect(PORT, kPORT_FilterKBI1, kPORT_BUSCLK_OR_NOFILTER);  /* Filter Selection for Input from KBI0: 0x01u */

 

    gpio_pin_config_t config = {
        kGPIO_DigitalOutput, 0,
    };

 

    GPIO_PinInit(kGPIO_PORTD, 1U, &config);

 

    PORT_SetPinPullUpEnable(PORT, kGPIO_PORTH, 7, 1); //Pull up pin 7
    PORT_SetPinPullUpEnable(PORT, kGPIO_PORTH, 6, 1);//Pull up pin 6

 

    kbiConfig.mode = kKBI_EdgesDetect;
    kbiConfig.pinsEnabled = (1 << EXAMPLE_KBI_PIN1) | (1 << EXAMPLE_KBI_PIN2);
    kbiConfig.pinsEdge = (1 << EXAMPLE_KBI_PIN1) | (1 << EXAMPLE_KBI_PIN2); // Rising edge.

 

   // kbiConfig.pinsEnabled = (0xC0000000) ;
   // kbiConfig.pinsEdge = (0xC0000000) ; // Rising edge.

 

    KBI_Init(EXAMPLE_KBI, &kbiConfig);

 

    while(1) {
         if (g_keypress)
         {
             g_keypress = false;
             delay();
             GPIO_PortToggle(kGPIO_PORTD, 1u << 1u);
         }
    }
    return 0 ;
}

 

I also attached the complete project as well.

I am using KBI1 but the same is happening if I use KBI0 as well.

I want to use atleast 5 buttons for this chip as external interrupts. Could you let me know it can be done for this chip.

Thanks

Attachments

Outcomes