STM8S时钟配置CLK_HSIPrescalerConfig与CLK_SYSCLKConfig区别

Posted heshengjun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了STM8S时钟配置CLK_HSIPrescalerConfig与CLK_SYSCLKConfig区别相关的知识,希望对你有一定的参考价值。

STM8S的时钟配置通过:CLK_CKDIVR寄存器,而CLK_CKDIVR一个是配置HSI分频,另一个是配置CPU的分频

 

static void CLK_Config(void)
{
CLK_DeInit();

/* Clock divider to HSI/1 */
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);  // 只配置HSI分频率,CPU分频率1   

/* Output Fcpu on CLK_CCO pin */
CLK_CCOConfig(CLK_OUTPUT_MASTER);
}

 


/**
* @brief Configure system clock to run at Maximum clock speed and output the
* system clock on CCO pin
* @param None
* @retval None
*/
static void CLK_Config(void)
{
ErrorStatus status = FALSE;

CLK_DeInit();

/* Configure the Fcpu to DIV1*/
CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);   // 配置CPU分频

/* Configure the HSI prescaler to the optimal value */
CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);  // 配置HSI分频

/* Output Fcpu on CLK_CCO pin */
CLK_CCOConfig(CLK_OUTPUT_CPU);

/* Configure the system clock to use HSE clock source and to run at 24Mhz */
status = CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);

while (ButtonPressed == FALSE)
{
}
/* Configure the system clock to use HSI clock source and to run at 16Mhz */
status = CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
}

 

 

 

// CLK_SYSCLKConfig通过CLK_Prescaler值的最高位来区分是配置HSI分频,还是CPU分频的。这个函数有两个功能。而CLK_HSIPrescalerConfig是直接配置HSI分频的,CPU分频配置成1

void CLK_SYSCLKConfig(CLK_Prescaler_TypeDef CLK_Prescaler)
{
/* check the parameters */
assert_param(IS_CLK_PRESCALER_OK(CLK_Prescaler));

if (((uint8_t)CLK_Prescaler & (uint8_t)0x80) == 0x00) /* Bit7 = 0 means HSI divider */
{
CLK->CKDIVR &= (uint8_t)(~CLK_CKDIVR_HSIDIV);
CLK->CKDIVR |= (uint8_t)((uint8_t)CLK_Prescaler & (uint8_t)CLK_CKDIVR_HSIDIV);
}
else /* Bit7 = 1 means CPU divider */
{
CLK->CKDIVR &= (uint8_t)(~CLK_CKDIVR_CPUDIV);
CLK->CKDIVR |= (uint8_t)((uint8_t)CLK_Prescaler & (uint8_t)CLK_CKDIVR_CPUDIV);
}
}

 

以上是关于STM8S时钟配置CLK_HSIPrescalerConfig与CLK_SYSCLKConfig区别的主要内容,如果未能解决你的问题,请参考以下文章

STM8S CPU主时钟

请教关于STM8S系列单片机死机问题?

STM8S208/207单片机芯片解密技术!

stm8s的iar如何和谐

stm8s的EEPROM读写程序如何编写,需要哪些配置步骤

最近在看STM8S单片机,头都大了,想请问下在STM8S中,