2013-05-27 06:58 AM
Hello ,
I want to try use a function that is without SysTick_Handler Interrupt : I wrote this function : void DelayUs(int us) { unsigned int cnt; while(us-- >0) { cnt = SysTick_GetCounter(); // get systick counter, ticking each 500nS while( (SysTick_GetCounter()-cnt) < 2); // repeat till 2 ticks } } but cnt value is zero , i can't see any value from SysTick_GetCounter() ; How can i solve this problem ? Does anyone have any advice ?2013-05-27 07:41 AM
show how you initialize the systick
2013-05-27 08:04 AM
I use this:
#define TICKSGN ((SysTick_VAL_CURRENT_Msk+1)>>1)
#define WAITMAX (SysTick_VAL_CURRENT_Msk >> 1)
static inline void waittick(uint32_t step)
{
static uint32_t tick0;
if (!step)
{
tick0 = SysTick->VAL;
return;
}
tick0 -= step;
while ((tick0 - SysTick->VAL) & TICKSGN)
{
__NOP();
__NOP();
}
}
static inline void sleep(uint32_t delay)
{
waittick(0);
delay++;
while (delay > WAITMAX)
{
waittick(WAITMAX);
delay -= WAITMAX;
}
waittick(delay);
}
2013-05-27 08:04 AM
SysTick_Config(SystemFrequency / 1000);
I only use this initializition function.2013-05-27 08:26 AM
Try my code above and initialize SysTick like this:
SysTick->LOAD = 0xffffff;
SysTick->CTRL = SysTick_CTRL_ENABLE_Msk;
Edit:
Thismay be better:
SysTick->LOAD = SysTick_VAL_CURRENT_Msk;
SysTick->CTRL = SysTick_CTRL_ENABLE_Msk;
2013-05-28 02:01 AM
SysTick_VAL_CURRENT_Msk;
SysTick_CTRL_ENABLE_Msk;
I couldn't find these variables on my project.
which library does include these variables?
2013-05-28 04:47 AM
It's defined in core_cm3.h