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

(0)

相关推荐