AnsweredAssumed Answered

TPM0 Timerinterrupt on MKL27Z

Question asked by Paul Targosz on Oct 21, 2016
Latest reply on Oct 25, 2016 by Robin_Shen

I'm using FRDM-KL27Z with Kinetis Design Studio

 

Somehow i dont get the Interrupt working. I'm sure to oversee something. 

 

 

#include "board.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "fsl_device_registers.h"

 

 

 

void TPM0_IRQHandler(void){
GPIOB->PTOR = 1 << 18;
TPM2->SC |= TPM_SC_TOF_MASK;
}

 

volatile int count;
int main(void) {

// Init board hardware.
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();

MCG->C1 = MCG_C1_IREFSTEN_MASK | MCG_C1_IRCLKEN_MASK;
MCG->C2 = MCG_C2_IRCS_MASK;
SIM->SCGC6 |= SIM_SCGC6_TPM0_MASK;
SIM->SOPT2 |= SIM_SOPT2_TPMSRC(3);

 

TPM0->SC = TPM_SC_CMOD(0) | TPM_SC_PS(7);
TPM0->MOD = 0xFF;

TPM0->SC |= TPM_SC_TOIE_MASK;


EnableIRQ(TPM0_IRQn);


SIM->SCGC5 |= SIM_SCGC5_PORTB_MASK;
PORTB->PCR[18] = PORT_PCR_MUX(1);

GPIOB->PDDR = 1 << 18;

TPM0->SC |= TPM_SC_TOF(1);


for(;;) { 
      count = TPM0->CNT;
   }
}

It compiles and the timer (cnt) is increasing.

TOF gets set too. Setting it to 0 (in debugtools) didnt help. its just 0 until it changes again to 1.

Outcomes