How to use external crystal?
Hi,
I want to run STM8S003F with an external crystal.
How do I use APIs in stm8_clk?
Or in which material is it described?
Regards,
Gotoda
Hi,
I want to run STM8S003F with an external crystal.
How do I use APIs in stm8_clk?
Or in which material is it described?
Regards,
Gotoda
So you see a signal on CLK_CCO. That means that either the crystal oscillator or the internal RC oscillator is functional. Since you see a 2 MHz signal that suggests that it is the internal RC oscillator, as by default its 16 MHz freq is divided by 8. And you do not divide the CLK_CCO signal. The odd thing is that you select HSE as the CLK_CCO signal, that doesn't make sense.
Can you give the code below a try? It works for me, although I did not have a 16 MHz crystal, but used an 8 MHz one.
The oscilloscope shows a (small) 8 MHz signal on both PA1 and PA2, Make sure to use a probe that doesn't load the oscillator too much (10x probe)
void HSE_config(void)
{
CLK_DeInit();
CLK_HSECmd(ENABLE);
CLK_LSICmd(DISABLE);
CLK_HSICmd(DISABLE);
while(CLK_GetFlagStatus(CLK_FLAG_HSERDY) == FALSE);
CLK_ClockSwitchCmd(ENABLE);
CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1);
CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSE,
DISABLE, CLK_CURRENTCLOCKSTATE_ENABLE);
}
void CLOCK_output(void)
{
CLK_CCOConfig(CLK_OUTPUT_CPUDIV8);
CLK_CCOCmd(ENABLE);
while(CLK_GetFlagStatus(CLK_FLAG_CCORDY) == FALSE);
}Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.