Help with Systick

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help with Systick

709 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by prancius on Sun Sep 16 04:33:05 MST 2012
Hello,

My code is for LPC11C24

 
 
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]#include [/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"driver_config.h"[/COLOR][/SIZE][/COLOR][/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]#include [/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"target_config.h"[/COLOR][/SIZE][/COLOR][/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]#include [/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"gpio.h"[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2] [/SIZE][SIZE=2] [/SIZE]

[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]volatile [/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#005032][SIZE=2][COLOR=#005032]uint32_t[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] msTicks; [/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int [/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]state=0;[/SIZE][/LEFT]
[/LEFT]

  
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void [/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][B]SysTick_Handler[/B] ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2])[/SIZE][/LEFT]
 
[LEFT][SIZE=2]{[/SIZE]

[SIZE=2]msTicks++; [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Increment counter[/COLOR][/SIZE][/COLOR][/SIZE]
[LEFT][SIZE=2]}[/SIZE][/LEFT]
[/LEFT]

[SIZE=2] [/SIZE]
[LEFT]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int [/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][B]main[/B] ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2])[/SIZE][/LEFT]
[/LEFT]

[SIZE=2]{[/SIZE]
 
[LEFT][SIZE=2]SystemInit ();[/SIZE][/LEFT]
 
[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Initialize clocks[/COLOR][/SIZE][/COLOR][/SIZE]

[SIZE=2]SysTick_Config (SystemCoreClock/1); [/SIZE][/LEFT]

 
 
 
[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Configure the SYSTICK[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]
 
 
[LEFT][SIZE=2]GPIOInit();[/SIZE][/LEFT]
 
 
 
[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/*[/COLOR][/SIZE][/COLOR][/SIZE]

[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]1 - output[/COLOR][/SIZE][/COLOR][/SIZE]
[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]0 - input[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
[SIZE=2][COLOR=#3f7f5f]*/[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]GPIOSetDir(0,7,1);[/SIZE][/LEFT]
[/LEFT]

 
 
 
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]while[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (1) [/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]/* Loop forever */[/COLOR][/SIZE][/COLOR][/SIZE]

[SIZE=2]{[/SIZE][/LEFT]

 
 
 
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (msTicks>10)[/SIZE]

[SIZE=2]{[/SIZE]
[LEFT][SIZE=2]msTicks=0;[/SIZE]
[SIZE=2]state=~state;[/SIZE]
[SIZE=2]GPIOSetValue( 0, 7, state);[/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
[/LEFT]

 

[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//__WFI();[/COLOR][/SIZE][/COLOR][/SIZE]
[LEFT][SIZE=2]}[/SIZE][/LEFT]
[/LEFT]

 
 
 
 
[LEFT][SIZE=2]}[/SIZE][/LEFT]
 
 


[LEFT]Any ideas why led do not blinks.
I run debugger but it never jump to timer handler. I think i missed something.[/LEFT]

[LEFT]Regards,
Pranas[/LEFT]
0 Kudos
9 Replies

630 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by prancius on Mon Sep 17 01:57:01 MST 2012
Thank you.
0 Kudos

630 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sun Sep 16 09:22:59 MST 2012
This sample shows how to use SysTick :o

...\LPCXpresso_4.2.3_292\lpcxpresso\Examples\NXP\LPC1000\LPC11xx\LPCXpresso1114_cmsis2.zip\LPCX1114_cmsis2_systick

Just change your MCU to LPC11C24 and it's working :)
0 Kudos

630 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ex-kayoda on Sun Sep 16 08:56:58 MST 2012

Quote: prancius
Hello,

So any good idea?
[SIZE=2]SysTick_Config (SystemCoreClock/1000); did not help.
[/SIZE]



#1 Post your complete project :mad:

#2 Is it a standard LPCXpresso project with CMSIS :confused:

#3 Is your SystemCoreClock defined :confused:

#4 Did you use Debugger to read SysTick values :eek:
0 Kudos

630 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ArtjomGromak on Sun Sep 16 08:41:22 MST 2012

Quote: prancius
Hello,

My code is for LPC11C24

 SysTick_Config (SystemCoreClock/1);




static __INLINE uint32_t SysTick_Config(uint32_t ticks)
{ 
  if (ticks > SysTick_LOAD_RELOAD_Msk)  return (1);            /* Reload value impossible */
                                                               
  SysTick->LOAD  = (ticks & SysTick_LOAD_RELOAD_Msk) - 1;      /* set reload register */
  NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1);  /* set Priority for Cortex-M0 System Interrupts */
  SysTick->VAL   = 0;                                          /* Load the SysTick Counter Value */
  SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk | 
                   SysTick_CTRL_TICKINT_Msk   | 
                   SysTick_CTRL_ENABLE_Msk;                    /* Enable SysTick IRQ and SysTick Timer */
  return (0);                                                  /* Function successful */
}

If your SystemCoreClock > 2^24 (16777216) then SysTick_Config do return without setting Systick (if (ticks > SysTick_LOAD_RELOAD_Msk)  return (1); )
What is SystemCoreClock in our program? 48000000 Hz?
Then SystemCoreClock/1 too big for SysTick_Config.
0 Kudos

630 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by prancius on Sun Sep 16 06:50:44 MST 2012
Hello,

So any good idea?
[SIZE=2]SysTick_Config (SystemCoreClock/1000); did not help.

I have done via

[SIZE=2][LEFT]SysTick->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LOAD[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=SystemCoreClock;
SysTick->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]VAL[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=0;[/LEFT]
SysTick->[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]CTRL[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=0x7;[/SIZE]
[SIZE=2][/SIZE]
[SIZE=2]But how to make it work via Systick_Config?
[/SIZE][/SIZE]
0 Kudos

630 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by graynomad on Sun Sep 16 06:14:13 MST 2012

Quote:
it is refused within SysTick_config


Yes I see that, as you say single stepping would have shown that.
0 Kudos

630 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ex-kayoda on Sun Sep 16 05:40:39 MST 2012

Quote: graynomad
You may be flashing at 500Hz and not seeing it although that doesn't explain not getting to the ISR in the debugger.




No :) Your code is fast, his code is nonsense, so it is refused within SysTick_config :p

A simple stepping will show that, reading return value also ;)
0 Kudos

630 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by graynomad on Sun Sep 16 05:24:28 MST 2012
I have similar code but I divided by 1000

[SIZE=2]SysTick_Config (SystemCoreClock/1000); [/SIZE]
You may be flashing at 500Hz and not seeing it although that doesn't explain not getting to the ISR in the debugger.
0 Kudos

630 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ex-kayoda on Sun Sep 16 05:16:29 MST 2012
Which frequency are you trying to set :confused:;):eek:

SysTick_Config (SystemCoreClock/1);  
Select SysTick_Config and jump with F3 to core_cm0.h, where this function is explained
0 Kudos