有关systick问题
时间:10-02
整理:3721RD
点击:
按照3.5库函数测试一下systick,发现所设置的延时与预期的不对。原本预期是1s灯转换一次状态,但实际上是9s左右转换一次。程序如下,求指点:
void SysTick_Configuration(void)
{
u32 a;
a = SystemCoreClock;
if(SysTick_Config(SystemCoreClock/1000))
while(1);
}
__IO uint32_t TimingDelay;
void Delay(__IO uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay!=0);
}
void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus;
RCC_DeInit();
RCC_HCLKConfig(RCC_HSE_ON);
if(RCC_WaitForHSEStartUp()==SUCCESS)
{
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_PCLK2Config(RCC_HCLK_Div1);
FLASH_SetLatency(FLASH_Latency_2);
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET);
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while(RCC_GetSYSCLKSource()!=0x08);
}
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);
}
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
SysTick_Configuration();
while (1)
{
GPIO_SetBits(GPIOF,GPIO_Pin_6);
Delay(1000); /*延时1s*/
GPIO_ResetBits(GPIOF,GPIO_Pin_6);
Delay(1000);
}
}
void SysTick_Configuration(void)
{
u32 a;
a = SystemCoreClock;
if(SysTick_Config(SystemCoreClock/1000))
while(1);
}
__IO uint32_t TimingDelay;
void Delay(__IO uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay!=0);
}
void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus;
RCC_DeInit();
RCC_HCLKConfig(RCC_HSE_ON);
if(RCC_WaitForHSEStartUp()==SUCCESS)
{
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_PCLK2Config(RCC_HCLK_Div1);
FLASH_SetLatency(FLASH_Latency_2);
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_9);
RCC_PLLCmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET);
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
while(RCC_GetSYSCLKSource()!=0x08);
}
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);
}
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
SysTick_Configuration();
while (1)
{
GPIO_SetBits(GPIOF,GPIO_Pin_6);
Delay(1000); /*延时1s*/
GPIO_ResetBits(GPIOF,GPIO_Pin_6);
Delay(1000);
}
}
看一下你使用的主频是多少 修改一下分频值就能得到1S了
用的HSE的8M晶振,SystemCoreClock=72000000