本帖最后由 kexd2004 于 2010-5-6 11:50 编辑
我用的芯片是stm32f101vbt6,只能工作在36MHz,我用的初始化函数都是开发板上移过来的(用的是103系列,即工作在72MHz),我的板子是能“正常”工作,加了引号是我的定时器2定时时间不对,想弱弱的问几个问题:
1.我初始化时钟为72MHz,板子也能工作,为什么呢
2.我试着修改RCC_Configuration(),再看定时器效果,慢了一半。不知是否已经成功修改了时钟为36MHz呢
void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus;
// Reset the RCC clock configuration to default reset state
RCC_DeInit();
// Configures the High Speed External oscillator
RCC_HSEConfig(RCC_HSE_ON);
// Waits for HSE start-up
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
// Enable Prefetch Buffer
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
// Sets the code latency value: FLASH Two Latency cycles
FLASH_SetLatency(FLASH_Latency_2);
// Configures the AHB clock(HCLK): HCLK = SYSCLK
RCC_HCLKConfig(RCC_SYSCLK_Div1);
// Configures the High Speed APB2 clcok(PCLK2): PCLK2 = HCLK
RCC_PCLK2Config(RCC_HCLK_Div1);
// Configures the Low Speed APB1 clock(PCLK1): PCLK1 = HCLK/2
RCC_PCLK1Config(RCC_HCLK_Div2);
// Configures the PLL clock source and multiplication factor
// PLLCLK = HSE*PLLMul = 8*9 = 72MHz
//RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);//原程序
RCC_PLLConfig(RCC_PLLSource_HSE_Div2, RCC_PLLMul_9);//my modify:测试看到time2 减慢一半,但到底是不是工作在 36 MHz?
// Enable PLL
RCC_PLLCmd(ENABLE);
// Checks whether the specified RCC flag is set or not
// Wait till PLL is ready
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
// Select PLL as system clock source
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
// Get System Clock Source
// Wait till PLL is used as system clock source
while(RCC_GetSYSCLKSource() != 0x08);
}
/* Enable Clock Security System(CSS) */
RCC_ClockSecuritySystemCmd(ENABLE); //new add:css(时钟安全系统),外部晶振失效时可以切换到HSI(内部RC)
} |