Kwikstik PIT1 interrupt not working

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

Kwikstik PIT1 interrupt not working

Jump to solution
1,109 Views
leandroc_rondon
Contributor II

Hi, I'm starting a development using the Kwikstik (K40).

I'm trying to raise two PIT interrupts (whit PIT0 and PIT1), but only the PIT0 handler function is being executed.

Could anyone help me and tell what is wrong?

Thank you.

void _PIT_Init(void)

{

  SIM_SCGC6 |= SIM_SCGC6_PIT_MASK;

  PIT_MCR &= ~PIT_MCR_MDIS_MASK;

  PIT_MCR |= PIT_MCR_FRZ_MASK;

}

void _PIT0_Init(void)

{

  PIT_LDVAL0 = 4000000; // 1s

  NVICISER2 |= (unsigned long)(84%32); 

  NVICICPR2 |= (unsigned long)(84%32);

  PIT_TCTRL0 |= PIT_TCTRL_TIE_MASK;

}

void _PIT0_Enable(void)

{

  PIT_TCTRL0 |= PIT_TCTRL_TEN_MASK;

}

void _PIT0_Disable(void)

{

  PIT_TCTRL0 &= ~PIT_TCTRL_TEN_MASK;

}

void _PIT1_Init(void)

{

  PIT_LDVAL1 = 4000000; // 1s

  NVICISER2 |= (unsigned long)(85%32);

  NVICICPR2 |= (unsigned long)(85%32);

  PIT_TCTRL1 |= PIT_TCTRL_TIE_MASK;

}

void _PIT1_Enable(void)

{

  PIT_TCTRL1 |= PIT_TCTRL_TEN_MASK;

}

void _PIT1_Disable(void)

{

  PIT_TCTRL1 &= ~PIT_TCTRL_TEN_MASK;

}

int main(void)

{

  _PIT_Init();

  _PIT0_Init();

  _PIT1_Init();

  _PIT0_Enable();

  _PIT1_Enable();

 

  /* Main loop */

  while(1)

  {

  }

}

void PIT0_IRQHandler(void)

{

  _PIT0_Disable();

  PIT_TFLG0 |= PIT_TFLG_TIF_MASK;

  _PIT0_Enable();

}

void PIT1_IRQHandler(void)

{

  _PIT1_Disable();

  PIT_TFLG1 |= PIT_TFLG_TIF_MASK;

  _PIT1_Enable();

}

Labels (1)
1 Solution
667 Views
Kan_Li
NXP TechSupport
NXP TechSupport

The NVIC enable interrupt function has some code issue. Please use the following instead.

void _PIT0_Init(void)

{

  PIT_LDVAL0 = 4000000; // 1s

  NVICISER2 |= (unsigned long)1<<(68%32);  

  NVICICPR2 |= (unsigned long)1<<(68%32);

  PIT_TCTRL0 |= PIT_TCTRL_TIE_MASK;

}

void _PIT1_Init(void)

{

  PIT_LDVAL1 = 4000000; // 1s

  NVICISER2 = (unsigned long)1<<(69%32);

  NVICICPR2 = (unsigned long)1<<(69%32);

  PIT_TCTRL1 |= PIT_TCTRL_TIE_MASK;

}

Hope that helps,

B.R

Kan

View solution in original post

3 Replies
667 Views
leandroc_rondon
Contributor II

I forgot to say: the PIT_TFLG1 TIF flag is set (even when I clear it by code or debugger), but the handler function is not called.

0 Kudos
668 Views
Kan_Li
NXP TechSupport
NXP TechSupport

The NVIC enable interrupt function has some code issue. Please use the following instead.

void _PIT0_Init(void)

{

  PIT_LDVAL0 = 4000000; // 1s

  NVICISER2 |= (unsigned long)1<<(68%32);  

  NVICICPR2 |= (unsigned long)1<<(68%32);

  PIT_TCTRL0 |= PIT_TCTRL_TIE_MASK;

}

void _PIT1_Init(void)

{

  PIT_LDVAL1 = 4000000; // 1s

  NVICISER2 = (unsigned long)1<<(69%32);

  NVICICPR2 = (unsigned long)1<<(69%32);

  PIT_TCTRL1 |= PIT_TCTRL_TIE_MASK;

}

Hope that helps,

B.R

Kan

667 Views
leandroc_rondon
Contributor II

It worked!

I got this code from a PIT example and forgot to do the most important thing: thinking!

Thank you, Kan Li :smileyhappy:

0 Kudos