stm8s cco flag never set
I have a discovery stm8s003k board and when I tested a program for cco capability it seems cco will never be stable and program always remain in line:
while(CLK_GetFlagStatus(CLK_FLAG_CCORDY) == FALSE);
code and more explain is in detail.
I tested it with below code and I even change pre-scalers for lower and higher frequency, I also check it with external crystal (and change the code) but it remains in
while(CLK_GetFlagStatus(CLK_FLAG_CCORDY) == FALSE);
forever.
When I debug the code and step over in debugger environment after the program enables CCOEN bit the output will start and frequency is just true. but both flag CCOBSY remains set (CCOR=0x69 in debugger) and it always remain in while loop.
when i try cco out put in stm 32 it is also seem unstable for example every thing is ok but every 8 clock one of clock has a little change in frequency or duty cycle ,what is problem with mco or cco section? thanks for reply.
My code is:
#include "STM8S.h"
#define LED_pin GPIO_PIN_0
#define LED_port GPIOD
void setup(void);
void clock_setup(void);
void GPIO_setup(void);
void main(void)
{
setup();
GPIO_WriteLow(LED_port, LED_pin);
while(TRUE){};
}
void setup(void)
{
clock_setup();
GPIO_setup();
}
void clock_setup(void)
{
CLK_DeInit();
CLK_HSECmd(DISABLE);
CLK_LSICmd(DISABLE);
CLK_HSICmd(ENABLE);
while(CLK_GetFlagStatus(CLK_FLAG_HSIRDY) == FALSE);
CLK_ClockSwitchCmd(ENABLE);
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV8);
CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV4);
CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO, CLK_SOURCE_HSI,
DISABLE, CLK_CURRENTCLOCKSTATE_ENABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_I2C, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_SPI, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART1, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_AWU, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_ADC, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER1, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2, DISABLE);
CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER4, DISABLE);
CLK_CCOConfig(CLK_OUTPUT_CPU);
CLK_CCOCmd(ENABLE);
while(CLK_GetFlagStatus(CLK_FLAG_CCORDY) == FALSE); //it remains here forever
}
void GPIO_setup(void)
{
GPIO_DeInit(LED_port);
GPIO_Init(LED_port, LED_pin, GPIO_MODE_OUT_OD_HIZ_FAST);
}
