Solved
What is the problem with this delay function?
Hi,
i'm trying to create a delay function for microsecond delays. But it doesn't work. I couldn't understand where the problem is. Could you please let me know?
(i'm using stmf030f4)
edit: To understand where the problem is i'm trying to create a milisecond delay function. And i set delay to 1000 miliseconds. But i see 8 seconds as a result. (and if set delay to 500 i see 4 seconds delay )
void delay_ticks(uint32_t ticks)
{
SysTick->LOAD = ticks;
SysTick->VAL = 0;
SysTick->CTRL = SysTick_CTRL_ENABLE_Msk;
// COUNTFLAG is a bit that is set to 1 when counter reaches 0.
// It's automatically cleared when read.
while ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == 0);
SysTick->CTRL = 0;
}
static inline void delay_ms(uint32_t ms)
{
delay_ticks((ms * 8000)); // number of ms*8000000 can overflow so i use 8000 instead of (ms * 8000000) / 1000)
} 

