想要用LPTMR0做一个ms级别的系统基准时钟,想法是:
LPTMR0时钟源为1000HZ,LPTMR0->CMR为1000,这样子每隔1S中断一次,在每次中断中SystemTickSecond++;
获取系统时钟的方法就是SystemTickSecond + LPTMR0->CNR
问题1:访问LPTMR0->CNR时硬件错误,必现。
原因:LPTMR0未初始化,未使能。在访问该寄存器前必须初始化。
问题2:LPTMR0中断 一次之后就不再计数,而且无法读取到ms的数值
原因:读取LPTMR0->CNR寄存器必须先有个写入。(The CNR returns the value of the LPTMR counter at the time this register was last written. Writing the
CNR will latch the current value of the LPTMR for subsequent reading, the value written is ignored.)
最终读取系统基准时钟的函数为:
unsigned long SystemTimeMs(void){