Kwikstik PIT1 interrupt not working

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

Kwikstik PIT1 interrupt not working

跳至解决方案
1,115 次查看
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();

}

标签 (1)
1 解答
673 次查看
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

在原帖中查看解决方案

3 回复数
673 次查看
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 项奖励
674 次查看
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

673 次查看
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 项奖励