|
写轮无语 发表于 2013-4-24 20:36
恩恩 看看你串口时钟那里 你超频后总线时钟变了啊
coreClk_mhz = pll_init();
unsigned char pll_init()
{
unsigned char pll_freq=0;
unsigned char reg=0;
// if (clk_option > 3) {return 0;} //return 0 if one of the available options is not selected
// if (crystal_val > 15) {return 1;} // return 1 if one of the available crystal options is not available
//This assumes that the MCG is in default FEI mode out of reset.
reg = MCG_S;
//========FEI to FBE mode============
// Enable external oscillator, RANGE=1 (1~8M oscillator), HGO=1, EREFS=1(oscillator request), LP=0, IRCS=0
MCG_C2 = MCG_C2_RANGE(1) | MCG_C2_HGO_MASK | MCG_C2_EREFS_MASK;
// Select external oscillator and Reference Divider and clear IREFS to start ext osc
// CLKS=2(external reference clk enable), FRDIV=2, IREFS=0
MCG_C1 = MCG_C1_CLKS(2) | MCG_C1_FRDIV(2);
while (!(MCG_S & MCG_S_OSCINIT_MASK)){reg = MCG_S ;}; //wait for OSCINIT to be set wait for crystal selected by C2[EREFS] has been initialized
while (MCG_S & MCG_S_IREFST_MASK){}; // wait for Reference clock Status bit to clear
while (((MCG_S & MCG_S_CLKST_MASK) >> MCG_S_CLKST_SHIFT) != 0x2){}; // Wait for clock status bits to show clock source is ext ref clk
MCG_C5 = MCG_C5_PRDIV(0); // 4MHz
//MCG_C5 = MCG_C5_PRDIV(1); // 2MHz
set_sys_dividers(0,2,2,7);//core
MCG_C6 = MCG_C6_PLLS_MASK | MCG_C6_VDIV(21);//4*45=180mhz
pll_freq = 180;
// set_sys_dividers(0,1,1,2); //MCG=PLL,
// MCG_C6 = MCG_C6_PLLS_MASK | MCG_C6_VDIV(4);//2*28=56mhz
// pll_freq = 56;
while(!(MCG_S & MCG_S_PLLST_MASK)){}; // wait PLLST to be set,indicating the current source for PLLS clock is PLL
while(!(MCG_S & MCG_S_LOCK_MASK)){}; //wait LOCK to be set, indicating the PLL has acquired lock.
//============PBE to PEE mode======================
MCG_C1 &= ~MCG_C1_CLKS_MASK; // select PLL as the system clock source.
while(((MCG_S & MCG_S_CLKST_MASK) >> MCG_S_CLKST_SHIFT) != 0x3){}; //wait for PLL output is selected to feed MCGOUT
//============MCGOUT CLK is set!======================================
return pll_freq;
} //pll_init
按照我这样的写法应该不用该串口时钟那边的程序了吧???
|
|