STM32中的systick,一共有4個寄存器,名稱和地址分別是:
SysTick_CTRL, 0xE000E010 -- 控制寄存器
SysTICK_LOAD, 0xE000E014 -- 重載寄存器
SysTick_VAL, 0xE000E018 -- 當前值寄存器
SysTick_CALRB, 0xE000E01C -- 校準值寄存器
首先看SysTick->CTRL控制寄存器:寄存器內有4個位具有意義
第0位:ENABLE,Systick 使能位 (0:關閉Systick功能;1:開啟Systick功能)
第1位:TICKINT,Systick 中斷使能位 (0:關閉Systick中斷;1:開啟Systick中斷)
第2位:CLKSOURCE,Systick時鐘源選擇 (0:使用HCLK/8 作為Systick時鐘;1:使用HCLK作為Systick時鐘)
第16位:COUNTFLAG,Systick計數比較標志,如果在上次讀取本寄存器后,SysTick 已經數到了0,則該位為1。如果讀取該位,該位將自動清零
SysTick_LOAD 重載寄存器:
SysTick_VAL當前值寄存器:
也是個24位的寄存器,讀取時返回當前倒計數的值;寫它則使之清零,同時還會清除在SysTick 控制及狀態寄存器中的COUNTFLAG 標志。
SysTick_CALRB 校準值寄存器:
這個寄存器好像目前的水平我還用不到,大體意思明白點,把英文說明放這吧:
位31 NOREF :1=沒有外部參考時鐘(STCLK 不可用)0=外部參考時鐘可用
位30 SKEW:1=校準值不是準確的1ms 0=校準值是準確的1ms
位[23:0] :Calibration value
Indicates the calibration value when the SysTick counter runs on HCLK max/8 as external clock. The value is product dependent, please refer to the Product Reference Manual, SysTick Calibration Value section. When HCLK is programmed at the maximum frequency, the SysTick period is 1ms. If calibration information is not known, calculate the calibration value required from the frequency of the processor clock or external clock.
類似matlab里的tic與toc函數,用來統計程序代碼執行需要的時間:
uint16_t OverFlowTimes=0;