不知道使用的对不对。新手,菜鸟~希望大神们解答一下
/**
* @brief This function is used to update the variable SystemCoreClock
* and must be called whenever the core clock is changed.
* @param None.
* @retval None.
*/
void SystemCoreClockUpdate (void)
{
uint32_t u32CoreFreq, u32ClkSrc;
// u32ClkSrc = CLK->CLKSEL0 & CLK_CLKSEL0_HCLK_S_Msk;
u32ClkSrc = 8;
if (u32ClkSrc == 0)
u32CoreFreq = __XTAL; /* External crystal clock */
else if (u32ClkSrc == 3)
u32CoreFreq = __IRC10K; /* Internal 10K crystal clock */
else if (u32ClkSrc == 7)
u32CoreFreq = __IRC22M; /* Internal 22M */
else
u32CoreFreq = __IRC22M; /* unknown value, use default Internal 22M */
SystemCoreClock = (u32CoreFreq/((CLK->CLKDIV & CLK_CLKDIV_HCLK_N_Msk) + 1));
CyclesPerUs = (SystemCoreClock + 500000) / 1000000;
}
这里 u32ClkSrc直接写了8.使用内部晶振,按理说内部应该是22.1184M的晶振。
但是在用官方代码给的定时延时的时候
/**
* @brief This function execute delay function.
* @param us Delay time. The Max value is 2^24 / CPU Clock(MHz). Ex:
* 50MHz => 335544us, 48MHz => 349525us, 28MHz => 699050us ...
* @return None
* @Details Use the SysTick to generate the delay time and the UNIT is in us.
* The SysTick clock source is from HCLK, i.e the same as system core clock.
*/
void CLK_SysTickDelay(uint32_t us) //MAX 1398101 US 12M MAX 758518 US 22.1184M MAX 762600 US 22M
{
SysTick->LOAD = us * CyclesPerUs;
SysTick->VAL = (0x00);
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk;
/* Waiting for down-count to zero */
while((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == 0);
SysTick->CTRL = 0;
}
按照计算,22.1184M最大可延时758518us。。但是实际上最大可以延时762600us.也就是内部晶振当成了22M。用的是MINI51系列的MINI54LDE官方版。得出是22M结论是板子上有个LED,自己写了程序闪烁。
请教一下内部晶振使用是否正确?如果正确为什么延时不对、希望大神解答一下
|