Kwikstik PIT1 interrupt not working

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Kwikstik PIT1 interrupt not working

ソリューションへジャンプ
1,029件の閲覧回数
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 解決策
587件の閲覧回数
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 返答(返信)
587件の閲覧回数
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 件の賞賛
588件の閲覧回数
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

587件の閲覧回数
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 件の賞賛