Interrupt in kl46Z

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

Interrupt in kl46Z

2,972 Views
bheemarao
Contributor II

I am working on freedom KL46Z board using interrupt on KDS3.0 with KSDK1.2.0

 

switch SW1 on freedom board is connected to PTC-3 and SW2 is conected to PTC-12 port pin

i have enable interrupts for the SW1 and SW2 on processor expert

when i generate a code i can see Events.c as below

void PORTC_PORTD_IRQHandler(void)

{

  PORT_HAL_ClearPortIntFlag(PORTC_BASE_PTR);

/* Write your code here ... */

}

 

how can i access individual interrupt from SW1 or SW2

i tried to identify interrupt from SW1 from function: GPIO_DRV_ReadPinInput(BUTTON_SW1)

but not able to identify the interrupt is from the source SW1 or SW2 ?

 

can any one has come across this scenario?

Labels (1)
0 Kudos
4 Replies

1,704 Views
yusufyelkovan
Contributor I

Also we can control multiple pin interrupt requests for the same port. There is an example code below which written directly to relevant registers for frdm_kl46z.

void PORTC_PORTD_IRQHandler(void){

      switch((uint32_t)PORTC_ISFR)       // to determine pin number look into PORTC_ISFR register.
      {
            case ((uint32_t)1<<SW1) :          // if SW1 button pressed
                  PORTC_PCR(SW1) |= PORT_PCR_ISF_MASK;       // Clear interrupt service flag in port control register otherwise int. remains active
                  GPIOD_PTOR |= GPIO_PTOR_PTTO(GreenLedMask);    // toggle Green LED
                  break;
            case ((uint32_t)1<<SW3) :          // if SW3 button pressed
                  PORTC_PCR(SW3) |= PORT_PCR_ISF_MASK;       // Clear interrupt service flag in port control register otherwise int. remains active
                  GPIOD_PTOR |= GPIO_PTOR_PTTO(RedLedMask);       // toggle Red LED
                  break;
            default :
                  PORTC_ISFR |= (0xFFFFFFFF);     // clear all flags to prevent being stuck in repetitive interrupt.
                  GPIOD_PTOR |= GPIO_PTOR_PTTO(RedLedMask);          // toggle Red LED
                  GPIOD_PTOR |= GPIO_PTOR_PTTO(GreenLedMask);      // toggle Green LED
                  break;

    }

}

and definitions like this :

#define RedLED    29     // PTE pin 29
#define GreenLED 5       // PTD pin 5
#define SW1          3       // PTC pin 3
#define SW3          12     // PTC pin 12
#define PORTC_D_IRQ_NBR (IRQn_Type)31 // IRQ number

const uint32_t GreenLedMask = (1<<GreenLED);
const uint32_t RedLedMask     = (1<<RedLED);
const uint32_t SW1Mask         = (1<<SW1);
const uint32_t SW3Mask         = (1<<SW3);

0 Kudos

1,704 Views
bheemarao
Contributor II

The mistake i was making is: i was clearing the interrupt flag using  " GPIO_DRV_ClearPinIntFlag(BUTTON_SW2);" which was not working i believe, we have to clear flag using "PORT_HAL_ClearPortIntFlag(PORTC_BASE_PTR);"

if(GPIO_DRV_IsPinIntPending(BUTTON_SW2)!=1){

   GPIO_DRV_TogglePinOutput(LED2_RED);

  // GPIO_DRV_ClearPinIntFlag(BUTTON_SW2);  //wrong way of clearing int flag

PORT_HAL_ClearPortIntFlag(PORTC_BASE_PTR);  // correct way which is working fine

  }

and instead of using the HAL " PORT_HAL_IsPinIntPending(PORTC_BASE_PTR, 3)" we can use "GPIO_DRV_IsPinIntPending(BUTTON_SW2)" which is user friendly.

0 Kudos

1,704 Views
EarlOrlando
Senior Contributor II

Hello Bheema,

You need to call the function PORT_HAL_IsPinIntPending (the second parameter is the pin) before to clear the flag.

Example:

void PORTC_PORTD_IRQHandler(void)

{

   if(PORT_HAL_IsPinIntPending(PORTC_BASE_PTR, 3))

   {

      PORT_HAL_ClearPinIntFlag(PORTC_BASE_PTR, 3);

      /* Write your code here ... */

   }

}

Best regards,

Earl.

/* If this post answers your question please click the Correct Answer button. */

0 Kudos

1,704 Views
bheemarao
Contributor II

Yes it worked fine for me.

Thanks for sharing

0 Kudos