我5438外接25MHz, 跑起来未发现问题。
void initClock(void)
{
// 初始化P7.0(#13)和P7.1(#14)为复用功能, XT1 外部时钟晶体接线
GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P7 , GPIO_PIN0 | GPIO_PIN1 );
// 启动XT1
//Initializes the XT1 crystal oscillator with no timeout
//In case of failure, code hangs here.
//For time-out instead of code hang use UCS_LFXT1StartWithTimeout()
UCS_LFXT1Start( UCS_XT1_DRIVE0 , UCS_XCAP_3);
// DCO参考时钟选择XT1,选择了默认参数
//UCS_clockSignalInit( UCS_FLLREF, UCS_XT1CLK_SELECT , UCS_CLOCK_DIVIDER_1 );
// 初始化P5.2(#89)和P5.3(#90)为复用功能, XT2 外部时钟晶体接线
GPIO_setAsPeripheralModuleFunctionInputPin( GPIO_PORT_P5 , GPIO_PIN2 | GPIO_PIN3 );
// 启动XT2
UCS_XT2Start( UCS_XT2DRIVE_24MHZ_32MHZ );
// DCO参考时钟选择XT1,选择了默认参数
//UCS_clockSignalInit( UCS_FLLREF, UCS_XT1CLK_SELECT , UCS_CLOCK_DIVIDER_1 );
// ACLK参考时钟源选择REFO, 32768Hz
//UCS_clockSignalInit(UCS_ACLK, UCS_REFOCLK_SELECT,UCS_CLOCK_DIVIDER_1);
// DCO参考时钟源选择REFO,32768Hz
//UCS_clockSignalInit(UCS_FLLREF, UCS_REFOCLK_SELECT , UCS_CLOCK_DIVIDER_1);
// DCO时钟16MHz, used as MCLK and SMCLK frequency
// 该函数第1个参数为系统工作频率 16384KHz/1024=16MHz,第2个参数为 工作频率/DCO参考频率=16*1024*1024/32768=512
#define FRQ_DIV 1
//UCS_initFLLSettle(16384/FRQ_DIV , 512/FRQ_DIV);
//! Initializes the XT2 crystal oscillator, which supports crystal frequencies
//! between 4 MHz and 32 MHz, depending on the selected drive strength. Loops
//! until all oscillator fault flags are cleared, with no timeout. See the
//! device-specific data sheet for appropriate drive settings.
UCS_clockSignalInit(UCS_MCLK,UCS_XT2CLK_SELECT ,UCS_CLOCK_DIVIDER_1);
//SMCLK参考时钟源选择DCO,16MHz/4=4MHz,4*1024*1024=4194304Hz
//UCS_clockSignalInit(UCS_SMCLK,UCS_DCOCLK_SELECT,UCS_CLOCK_DIVIDER_4);
UCS_clockSignalInit(UCS_SMCLK,UCS_XT2CLK_SELECT,UCS_CLOCK_DIVIDER_4);
//延时0.5秒, 让时钟源稳定
delay_ms(500);
UCS_setExternalClockSource(32768,MCLK_FRQ);
cvMCLK = UCS_getMCLK();
cvSMCLK = UCS_getSMCLK();
cvACLK = UCS_getACLK();
}
|