kl43z timer issue

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

kl43z timer issue

跳至解决方案
1,353 次查看
kennethgraakjær
Contributor II

Hi

I'm trying to do a bare bones timer setup on the frdm kl43z board.

In my source I have:

#include "fsl_device_registers.h"

int main() {

     TPM2_SC |= TPM_SC_PS(0x7);    // prescaler at 128.

     /* other stuff */

}

However when I encounter the above line in debug mode it triggers the default interrupt handler. This is the same for all timers TPM0 - 2.

Any ideas as to what I'm missing?

标记 (2)
0 项奖励
回复
1 解答
1,235 次查看
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Kenneth Graakjaer:

Have you enabled the clock gate for TPM2?

This must be done before configuring any TPM2 register. The line of code would be this:

SIM_SCGC6 |= SIM_SCGC6_TPM2_MASK;

This applies to any peripheral; before accesing the registers you have to enable the clock gates.


Regards!,
Jorge Gonzalez

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

在原帖中查看解决方案

0 项奖励
回复
2 回复数
1,236 次查看
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Kenneth Graakjaer:

Have you enabled the clock gate for TPM2?

This must be done before configuring any TPM2 register. The line of code would be this:

SIM_SCGC6 |= SIM_SCGC6_TPM2_MASK;

This applies to any peripheral; before accesing the registers you have to enable the clock gates.


Regards!,
Jorge Gonzalez

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复
1,235 次查看
kennethgraakjær
Contributor II

Worked like a charm! Thank you.

I had the clock source in SIM_SOPT2 confused with the clock gate.

0 项奖励
回复