KL25Z, SysTick problem.

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

KL25Z, SysTick problem.

2,867 Views
madagaskar
Contributor II

Hello everyone,

bellow I wrote my SysTick code. It's works but i have problem with time couting:

#include "derivative.h"

void SysTick_Handler()

{

     //LED TOGGLE

     GPIOB_PTOR |= (1<<0);

}

     int main(void){

     SYST_RVR = SysTick_RVR_RELOAD(6000000);

     SYST_CVR = SysTick_CVR_CURRENT(0);

     SYST_CSR |= SysTick_CSR_ENABLE_MASK | SysTick_CSR_TICKINT_MASK | SysTick_CSR_CLKSOURCE_SHIFT;

     for(;;){}

     return 0;

}

Default i have 48MHz system clock and 8MHz external oscillator. Why LED doesn't toggle once for a second (now it's mutch longer)? Maybe I forgot about something important?

Tags (2)
0 Kudos
Reply
8 Replies

1,377 Views
hunter18
Contributor II

What is the content of your derivatives.h? can you upload it? thanks.

0 Kudos
Reply

1,377 Views
madagaskar
Contributor II

To set processor clock I used code from example project.;) You said that the red led blinks at about 1Hz. I'm realy suprising because it's still doesn't work correctly.:/ Maybe it's hardware problem...

0 Kudos
Reply

1,377 Views
ndavies
Contributor V

The problem is with the SysTick_CSR_CLKSOURCE_SHIFT being orred into SYST_CSR. It actually needs to be SysTick_CSR_CLKSOURCE_MASK or (1<<SysTick_CSR_CLKSOURCE_SHIFT)

0 Kudos
Reply

1,377 Views
madagaskar
Contributor II

When I wrote:

SYST_CSR |= SysTick_CSR_ENABLE_MASK | SysTick_CSR_TICKINT_MASK | SysTick_CSR_CLKSOURCE_MASK;

I only changed frequency source from external reference clock to processor clock. Of course again i didn't have one second toggling. It look's like problem with processor clock frequency. Maybe default it doesn't be a 48MHz? Or I should count new value for SysTick_RVR_RELOAD ?(I tried but it doesn't help) Now I haven't any different idea how to fix it.:/

0 Kudos
Reply

1,377 Views
JimDon
Senior Contributor III

How are you initializing the clock? You need code to set 48Mhz, in other words, the processor does not "default" to 48 Mhz.

Where is LED connected? Hard to say if the code is correct if you don't tell us more.

If the systick is running from a 48Mhz processor, then 6,000,000 will give 8 ticks per second. Note that this counter is only 24 bits, so you can't get a 1 second tick from a 48Mhz clock.

0 Kudos
Reply

1,377 Views
madagaskar
Contributor II

I didn't initialize the clock because I was thinking that it wasn't necessary. I found an example for systick and they use Multipurpose Clock Generator module(MCG) but it's still doesn't work. Maybe you could write me a code to set processor clock or some more advices how can I do that with reference manual? And one more question. What is the value of processor clock frequency when I don't initialize the clock? In systick.rar is my project.

0 Kudos
Reply

1,377 Views
JimDon
Senior Contributor III

When I run your project the RED led blinks at about 1HZ, so there is really nothing for me to tell you to change.

:smileyhappy:

Also, on the GPIOB_PCOR, GPIOB_PSOR and GPIOB_PTOR register you should NOT use the 'or' operator, as these registers only change bits that are a "1", so read/modify/write is not required and could cause problems (it is ok in this case as read returns all 0's). Bits that are 0 cause no change. There are some registers that are only change on 1 that do not read back 0's. In any event, it does waste cycles.

You did a great job of figuring this out on your own.

0 Kudos
Reply

1,377 Views
zhaohuiliu
NXP Employee
NXP Employee

you should set 1's to GPIOB_PTOR related bit to toggle an IO.

Try this,

void SysTick_Handler()

{

     //LED TOGGLE

     GPIOB_PTOR |= (1<<1);

}


0 Kudos
Reply