How to configure correctly the STM8S005C6 clock to use the HSI oscilator at 16Mhz?
- August 18, 2020
- 1 reply
- 1452 views
Using the library functions the micro freezes and enters a CLK assert, this is the code I use to configure the CLK:
CLK_DeInit ();
CLK_HSECmd (DISABLE);
CLK_LSICmd (DISABLE);
CLK_HSICmd (ENABLE);
while (! CLK_GetFlagStatus (CLK_FLAG_HSIRDY));
CLK_ClockSwitchCmd (ENABLE);
CLK_HSIPrescalerConfig (CLK_PRESCALER_HSIDIV1);
CLK_SYSCLKConfig (CLK_PRESCALER_CPUDIV1);
CLK_ClockSwitchConfig (CLK_SWITCHMODE_AUTO,
CLK_SOURCE_HSI,
DISABLE,
CLK_CURRENTCLOCKSTATE_ENABLE);
CLK_PeripheralClockConfig (CLK_PERIPHERAL_SPI, DISABLE);
CLK_PeripheralClockConfig (CLK_PERIPHERAL_I2C, DISABLE);
CLK_PeripheralClockConfig (CLK_PERIPHERAL_ADC, DISABLE);
CLK_PeripheralClockConfig (CLK_PERIPHERAL_AWU, DISABLE);
CLK_PeripheralClockConfig (CLK_PERIPHERAL_UART1, DISABLE);
CLK_PeripheralClockConfig (CLK_PERIPHERAL_TIMER1, DISABLE);
CLK_PeripheralClockConfig (CLK_PERIPHERAL_TIMER2, DISABLE);
CLK_PeripheralClockConfig (CLK_PERIPHERAL_TIMER4, DISABLE);
When I just change the divider of the CLK_HSIPrescaler or CLK_SYSCLKConfig everything works but at a lower frequency than desired.
Would you know how to do the right configuration to make it run at 16Mhz?
All the parameters of the datasheet are respected, use of the STVD with the Cosmic Compiler 8. Windows 7 operating system. The test project is attached to this question.
Thanks in advance to ST community.
