cancel
Showing results for 
Search instead for 
Did you mean: 

systick_config(systemcoreclock / 1000) generate interrupt every 2ms ?

cnurettin
Associate
Posted on December 18, 2014 at 15:20

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 32000000

But 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-config
3 REPLIES 3
stm322399
Senior
Posted on December 18, 2014 at 15:30

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.

Posted on December 18, 2014 at 16:49

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.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cnurettin
Associate
Posted on December 19, 2014 at 09:43

Thank you 0690X0000060MmyQAE.gifandclive1 .

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...