kl43z timer issue

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

kl43z timer issue

Jump to solution
611 Views
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?

Tags (2)
0 Kudos
1 Solution
493 Views
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!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
2 Replies
494 Views
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 Kudos
493 Views
kennethgraakjær
Contributor II

Worked like a charm! Thank you.

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

0 Kudos