|
看例程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指针的问题?
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。
|