看例程HelloWorld用LPTMR初始化一定时器:
// LPTMR configurations
lptmr_user_config_t lptmrConfig =
{
.timerMode = kLptmrTimerModeTimeCounter,
.freeRunningEnable = false,
.prescalerEnable = true,
.prescalerClockSource = kClockLptmrSrcLpoClk,
.prescalerValue = kLptmrPrescalerDivide2,
.isInterruptEnabled = true,
};
lptmr_state_t lptmrState; // LPTMR driver state information
LPTMR_DRV_Init(LPTMR0_IDX, &lptmrState, &lptmrConfig); // Initialize LPTMR
LPTMR_DRV_SetTimerPeriodUs(LPTMR0_IDX, TMR_PERIOD); // Set timer period for TMR_PERIOD seconds
LPTMR_DRV_InstallCallback(LPTMR0_IDX, lptmr_call_back); // Install interrupt call back function for LPTMR
LPTMR_DRV_Start(LPTMR0_IDX); // Start LPTMR
将这段代码放在main()中可以正确初始化LPTMR,可在中断中闪烁一LED。
但将这段代码放在一函数中,如:
void lptmr_func(void)
{
// LPTMR configurations
lptmr_user_config_t lptmrConfig =
{
.timerMode = kLptmrTimerModeTimeCounter,
.freeRunningEnable = false,
.prescalerEnable = true,
.prescalerClockSource = kClockLptmrSrcLpoClk,
.prescalerValue = kLptmrPrescalerDivide2,
.isInterruptEnabled = true,
};
lptmr_state_t lptmrState; // LPTMR driver state information
LPTMR_DRV_Init(LPTMR0_IDX, &lptmrState, &lptmrConfig); // Initialize LPTMR
LPTMR_DRV_SetTimerPeriodUs(LPTMR0_IDX, TMR_PERIOD); // Set timer period for TMR_PERIOD seconds
LPTMR_DRV_InstallCallback(LPTMR0_IDX, lptmr_call_back); // Install interrupt call back function for LPTMR
LPTMR_DRV_Start(LPTMR0_IDX); // Start LPTMR
}
再在main()中调用lptrm_func(),则无法正确初始化LPTMR。
查API Reference,原型为:
不是是否是const指针的问题?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
比FSL FAE都强
一周热门 更多>