F28027第二節課---系統時鐘(一)
本來今天打算學習GPIO的,但看了相關的文件和案例後,發現跟系統的時鐘有關聯,所以今天先學習時鐘這章節
我是一個比較浮躁的人,需要什麼看什麼,所以直接翻開案例文件,主函式第一個條語句就是InitSysCtrl(),所以今晚先分析F2802x_SysCtrl.c這個檔案
首先看下系統時鐘初始化函式InitSysCtrl()這個函式包含哪些內容:
void InitSysCtrl(void)
{
// Disable the watchdog
DisableDog();
// *IMPORTANT*
// The Device_cal function, which copies the ADC & oscillator calibration values
// from TI reserved OTP into the appropriate trim registers, occurs automatically
// in the Boot ROM. If the boot ROM code is bypassed during the debug process, the
// following function MUST be called for the ADC and oscillators to function according
// to specification. The clocks to the ADC MUST be enabled before calling this
// function.
// See the device data manual and/or the ADC Reference
// Manual for more information.
EALLOW;
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1; // Enable ADC peripheral clock
(*Device_cal)();
SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 0; // Return ADC clock to original state
EDIS;
// Select Internal Oscillator 1 as Clock Source (default), and turn off all unused clocks to
// conserve power.
IntOsc1Sel();
// Initialize the PLL control: PLLCR and DIVSEL
// DSP28_PLLCR and DSP28_DIVSEL are defined in DSP2802x_Examples.h
InitPll(DSP28_PLLCR,DSP28_DIVSEL);
// Initialize the peripheral clocks
InitPeripheralClocks();
}
第一、關閉看門狗
void DisableDog(void)
{
EALLOW;
SysCtrlRegs.WDCR= 0x0068;
EDIS;
}
EALLOW/EDIS指令說明該暫存器被防寫了
下面來看下看門狗控制暫存器WDCR的結構:
暫存器說明如上所示,現在要關閉watchdog,所以使能位WDDIS要置1,而時鐘檢測位WDCHK預設情況下必須寫入101,時鐘預分頻就寫為預設000,合起來WDCR就要寫入0x0068
第二、內部振盪器(時鐘源)配置
源程式中第二步是ADC時鐘初始化,我們這裡先跳過,直接到IntOsc1Sel()
void IntOsc1Sel (void) {
EALLOW;
SysCtrlRegs.CLKCTL.bit.INTOSC1OFF = 0;
SysCtrlRegs.CLKCTL.bit.OSCCLKSRCSEL=0; // Clk Src = INTOSC1
SysCtrlRegs.CLKCTL.bit.XCLKINOFF=1; // Turn off XCLKIN
SysCtrlRegs.CLKCTL.bit.XTALOSCOFF=1; // Turn off XTALOSC
SysCtrlRegs.CLKCTL.bit.INTOSC2OFF=1; // Turn off INTOSC2
EDIS;
}
我們先看下系統時鐘源結構圖:
其中INTOSC1、INTOSC2:片內,可為WatchDog、CPU、Timer2提供時鐘,晶體振盪器:X1、X2引腳外部接晶振提供時基,外部時鐘源:通過XCLKIN引腳輸入外部時鐘源
瞭解了時鐘源問題,我們現在來看下CLKCTL這個暫存器的結構圖:
暫存器位說明都已經看到了,我們現在的函式名是IntOsc1Sel(),說明我們要以內部振盪器1為時鐘源,目的很明確了,開內1,關內2、關外部輸入、關晶體振盪器輸入,也就是INTOSC1OFF = 0、OSCCLKSRCSEL=0、XCLKINOFF=1、XTALOSCOFF=1、INTOSC2OFF=1
菜鳥交流qq群:107691092