2014-08-29 11:15 AM
Hi, I can manage to change clock from HSI>HSE and vice versa. But I am not able to bring LSI as my master clock. Can anyone help please?
I am using STM8S Discovery board and Cosmic C as my compiler.My code is as follows:/* MAIN.C file * * Copyright (c) 2002-2005 STMicroelectronics */&sharpinclude ''stm8s.h''u16 c=50000;u8 i;main(){ ErrorStatus status; CLK_DeInit(); CLK_HSICmd(ENABLE); while (CLK_GetFlagStatus(CLK_FLAG_HSIRDY)==0); CLK_LSICmd(ENABLE); while (CLK_GetFlagStatus(CLK_FLAG_LSIRDY)==0); CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV1); CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV8); CLK_ClockSwitchCmd(ENABLE); CLK_CCOConfig(CLK_OUTPUT_MASTER); CLK_CCOCmd(ENABLE); GPIO_DeInit (GPIOD); GPIO_Init (GPIOD,GPIO_PIN_0,GPIO_MODE_OUT_PP_LOW_FAST);while (1){// CLK_PeripheralClockConfig(CLK_PERIPHERAL_TIMER2,ENABLE);// TIM2_DeInit();// TIM2_TimeBaseInit(TIM2_PRESCALER_2048, 300);// TIM2_Cmd(ENABLE); for(i=0;i<10;i++){// if (TIM2_GetCounter()>150){// GPIO_WriteHigh(GPIOD,GPIO_PIN_0);// } // else {// GPIO_WriteLow(GPIOD,GPIO_PIN_0);// } while (c>1){ c--; } c=50000; GPIO_WriteReverse(GPIOD,GPIO_PIN_0); } status=CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO,CLK_SOURCE_HSE,DISABLE,CLK_CURRENTCLOCKSTATE_ENABLE); for(i=0;i<10;i++){// if (TIM2_GetCounter()>150){// GPIO_WriteHigh(GPIOD,GPIO_PIN_0);// } // else {// GPIO_WriteLow(GPIOD,GPIO_PIN_0);// } while (c>1){ c--; } c=50000; GPIO_WriteReverse(GPIOD,GPIO_PIN_0); } status=CLK_ClockSwitchConfig(CLK_SWITCHMODE_AUTO,CLK_SOURCE_LSI,DISABLE,CLK_CURRENTCLOCKSTATE_ENABLE);}}&sharpifdef USE_FULL_ASSERT/** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t* file, uint32_t line){ /* User can add his own implementation to report the file name and line number, ex: printf(''Wrong parameters value: file %s on line %d\r\n'', file, line) */ /* Infinite loop */ while (1) { }}&sharpendif #lsi-clock-source2017-03-20 02:42 AM
Make sure the option bytes are set to enable the LSI. See datasheet for description of option bytes.