MSP430(F5529)學習筆記——UCS配置詳解
理解了上面這些,可以理解TI官方例子中的代碼了,官方代碼中的相關部分如下:
[cpp]view plaincopy
- if(fsystem<=630)//fsystem<0.63MHz
- UCSCTL1=DCORSEL_0;
- elseif(fsystem<1250)//0.63MHz
- UCSCTL1=DCORSEL_1;
- elseif(fsystem<2500)//1.25MHz
- UCSCTL1=DCORSEL_2;
- elseif(fsystem<5000)//2.5MHz
- UCSCTL1=DCORSEL_3;
- elseif(fsystem<10000)//5MHz
- UCSCTL1=DCORSEL_4;
- elseif(fsystem<20000)//10MHz
- UCSCTL1=DCORSEL_5;
- elseif(fsystem<40000)//20MHz
- UCSCTL1=DCORSEL_6;
- else
- UCSCTL1=DCORSEL_7;
都在前面講到的范圍內(nèi),由于前面的范圍有重疊部分,例子代碼中的值是TI的工程師根據(jù)上面這些參數(shù)選取的比較合理的值。
到這里,我相信大家配合芯片手冊和本文,都能明白DCO配置相關部分的原理了,下面是將DCO參考時鐘選為XT1,并將DCOCLK倍頻到25M的詳細代碼:
[cpp]view plaincopy
- #include
- voiddelay(){
- volatileunsignedinti;
- for(i=0;i!=5000;++i){
- _NOP();
- }
- }
- voidSetVcoreUp(unsignedintlevel)
- {
- //OpenPMMregistersforwrite
- PMMCTL0_H=PMMPW_H;
- //SetSVS/SVMhighsidenewlevel
- SVSMHCTL=SVSHE+SVSHRVL0*level+SVMHE+SVSMHRRL0*level;
- //SetSVMlowsidetonewlevel
- SVSMLCTL=SVSLE+SVMLE+SVSMLRRL0*level;
- //WaittillSVMissettled
- while((PMMIFG&SVSMLDLYIFG)==0);
- //Clearalreadysetflags
- PMMIFG&=~(SVMLVLRIFG+SVMLIFG);
- //SetVCoretonewlevel
- PMMCTL0_L=PMMCOREV0*level;
- //Waittillnewlevelreached
- if((PMMIFG&SVMLIFG))
- while((PMMIFG&SVMLVLRIFG)==0);
- //SetSVS/SVMlowsidetonewlevel
- SVSMLCTL=SVSLE+SVSLRVL0*level+SVMLE+SVSMLRRL0*level;
- //LockPMMregistersforwriteaccess
- PMMCTL0_H=0x00;
- }
- voidmain(void){
- WDTCTL=WDTPW+WDTHOLD;
- P1SEL&=~BIT1;
- P1DIR|=BIT1;
- P1SEL|=BIT0;//ACLK
- P1DIR|=BIT0;
- P2SEL|=BIT2;//SMCLK
- P2DIR|=BIT2;
- P7SEL|=BIT7;//MCLK
- P7DIR|=BIT7;
- P5SEL|=BIT4|BIT5;
- UCSCTL6|=XCAP_3;
- UCSCTL6&=~XT1OFF;
- SetVcoreUp(1);//一次提高Vcore電壓等級,具體請參考手冊
- SetVcoreUp(2);
- SetVcoreUp(3);
- __bis_SR_register(SCG0);
- UCSCTL0=0;
- UCSCTL1=DCORSEL_6;
- UCSCTL2=FLLD_1|380;
- __bic_SR_register(SCG0);
- __delay_cycles(782000);
- /*
- *默認狀態(tài)下:ACLK=FLLREFCLK=XT1SMCLK=MCLK=DCOCLKDIVXT2關閉
- *為了不產(chǎn)生XT1LFOFFG,將ACLK和FLLREFCLK設置為REFOCLK
- *并打開XT2OFF,否則XT2將處于無法使用狀態(tài)
- **/
- //UCSCTL6&=~(XT2DRIVE0|XT2DRIVE1|XT2OFF);
- while(SFRIFG1&OFIFG){//CheckOFIFGfaultflag
- UCSCTL7&=~(XT2OFFG+XT1LFOFFG+DCOFFG);//ClearOSCflautFlags
- SFRIFG1&=~OFIFG;//ClearOFIFGfaultflag
- }
- UCSCTL4=UCSCTL4&(~(SELS_7|SELM_7))|SELS_3|SELM_3;
- while(1){
- P1OUT^=BIT1;
- delay();
- }
- }
好了,經(jīng)過上面的四個實驗,我們都能正確使用MSP430F5XX的UCS了,如果有什么疑問,歡迎留言討論。
評論