FRDM_KL02Z TPM0 Timer Overflow Interrupt not working.

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

FRDM_KL02Z TPM0 Timer Overflow Interrupt not working.

351 次查看
SoloTheDog
Contributor I

All of the registers seem to be set properly, and the TOF register is properly set when the timer overflows. I can poll it and manually clear it in main, but the TPM0_IRQHandler() doesn't get called. I tried the SDK example that uses the same interrupt and it also doesn't work, so don't think it is an issue in code. What else can I look at to get this working?

I'm using the fsl_tpm.h driver.

here is the initTimer() code that setups up TPM0_IRQHandler().

 

 

#include "fsl_tpm.h"
#include "timer.h"
#include "fsl_gpio.h"
#include "pin_mux.h"
#include "stdio.h"

void initTimer()
{
    tpm_config_t tpmConfig;
    TPM_GetDefaultConfig(&tpmConfig);
    tpmConfig.prescale = kTPM_Prescale_Divide_128;

    NVIC_SetPriority(TPM0_IRQn, 3);
    NVIC_EnableIRQ(TPM0_IRQn);

    TPM_Init(TPM0, &tpmConfig);

    uint32_t tpmClock = TPM_SOURCE_CLOCK;
    uint32_t timerPeriod = USEC_TO_COUNT(1000U, tpmClock) / 128; // 1ms

    TPM_EnableInterrupts(TPM0, kTPM_TimeOverflowInterruptEnable);

    TPM_SetTimerPeriod(TPM0, timerPeriod);
    TPM_StartTimer(TPM0, kTPM_SystemClock);
}

volatile uint32_t elapsedTime = 0;

void TPM0_IRQHandler()
{
    TPM_ClearStatusFlags(TPM0, kTPM_TimeOverflowFlag);
    GPIO_PortToggle(BOARD_INITPINS_LED_RED_GPIO, 1u << BOARD_INITPINS_LED_RED_PIN);
}

 

 

 

0 项奖励
回复
1 回复

317 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi,

Pls set the TOIE bit in TPMx_SC reg as the following Fig:

xiangjun_rong_0-1711940626222.png

 

I suppose that the bit can be initialized by the structure

tpmConfig

Hope it can help you

BR

XiangJun Rong

0 项奖励
回复