2014-12-18 06:20 AM
Hi all,
I use STM32L152 with discovery board and my compiler is KEIL. I know that if we use below code interrupt will occured every 1 ms. systick_config(systemcoreclock / 1000) ; // systemcoreclock set 32000000But in my code every 2 ms .This is my basic code :/* Main while loop */while(1) { if (system_time-led_blue_time>=1000) { LED_BLUE_TOGGLE; led_blue_time=system_time; }/* Interrupt */void SysTick_Handler(void){ system_time++;} Finally i see 2 seconds led on and 2 seconds led off periodical instead of 1 seconds.What is my wrong.Thanks all. #systick-config2014-12-18 06:30 AM
You probably run the target at 16MHZ. Double check clock settings (HSI is at 16MHz), PLL settings and main clock selector. Try to configure PA8 as MCO to get an output of internal clock and check the frequency with an o-scope.
Can you use UART ? try to output chars at 115200 and check the real baudrate on o-scope.2014-12-18 07:49 AM
If SystemCoreClock is wrong, then you'd need to revisit the code in, and called by, SystemInit() in system_stm32l1xx.c. You are interested in the clocks selected, started, and the PLL settings and lock.
You could also use RCC_GetClocksFreq() to calculate the clocks the system believes it's using. If the HSE clock is used, then HSE_VALUE needs to reflect the speed of the external crystal/source. On the STM32L1-DISCO this is likely 8MHz, either from a crystal or the MCO output of the ST-LINK processor.2014-12-19 12:43 AM
Thank you andclive1 .
Firstly i usedRCC_GetClocksFreq() code for check what am i really using . I saw that SystemClock was 16 MHz. Then i changed my systick config as below : void Config_Systick() { RCC_ClocksTypeDef RCC_Clocks; RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency/1000); // SysTick interrupt set 1ms } Now i have interrupt every 1 ms. Thanks again...