Question
Hi All, I am new to STM8L controller, Could you help me out with the clock configuration part? I am using STM8L152R8T6 controller Eval Kit along with Cosmic Compiler. Trying to do simple LED toggling on this board but unable to perform it.
void main()
{
uint32_t clockFrequency = 0x0000;
//clock enable for MCU
/* Select HSE as system clock source */
CLK_HSICmd(ENABLE);
CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);
/* system clock prescaler: 1*/
CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);
while (CLK_GetSYSCLKSource() != CLK_SYSCLKSource_HSI);
clockFrequency = CLK_GetClockFreq();
GPIO_Init(GPIOA, GPIO_Pin_All, GPIO_Mode_Out_OD_Low_Fast);
GPIO_Init(GPIOB, GPIO_Pin_All, GPIO_Mode_Out_OD_Low_Fast);
GPIO_Init(GPIOC, GPIO_Pin_All, GPIO_Mode_Out_OD_Low_Fast);
GPIO_Init(GPIOD, GPIO_Pin_All, GPIO_Mode_Out_OD_Low_Fast);
GPIO_Init(GPIOE, GPIO_Pin_All, GPIO_Mode_Out_OD_Low_Fast);
GPIO_Init(GPIOF, GPIO_Pin_All, GPIO_Mode_Out_OD_Low_Fast);
GPIO_Init(GPIOG, GPIO_Pin_All, GPIO_Mode_Out_OD_Low_Fast);
GPIO_Init(GPIOH, GPIO_Pin_All, GPIO_Mode_Out_OD_Low_Fast);
GPIO_Init(GPIOI, GPIO_Pin_All, GPIO_Mode_Out_OD_Low_Fast);
while (1)
{
GPIO_Write(GPIOA, 0xff);
GPIO_Write(GPIOB, 0xff);
GPIO_Write(GPIOC, 0xff);
GPIO_Write(GPIOD, 0xff);
GPIO_Write(GPIOE, 0xff);
GPIO_Write(GPIOF, 0xff);
GPIO_Write(GPIOG, 0xff);
GPIO_Write(GPIOH, 0xff);
GPIO_Write(GPIOI, 0xff);
Delay(1000);Delay(1000);
GPIO_Write(GPIOA, 0x00);
GPIO_Write(GPIOB, 0x00);
GPIO_Write(GPIOC, 0x00);
GPIO_Write(GPIOD, 0x00);
GPIO_Write(GPIOE, 0x00);
GPIO_Write(GPIOF, 0x00);
GPIO_Write(GPIOG, 0x00);
GPIO_Write(GPIOH, 0x00);
GPIO_Write(GPIOI, 0x00);
Delay(1000);Delay(1000);
}
}Above is the code I am working on. One more interesting point, even clockFrequency set to zero it is always showing some random value after initialization and after clockFrequency = CLK_GetClockFreq() line.
Could anyone help me out? Where I am doing wrong?
Thanks!!!