2015-05-21 11:11 PM
Hi Folks!
I have a Problem with the Systick Timer. I use it to handle some periodic functions. The SysTick Timer is configured to 500us. Everything works fine. Now I need a delay function. When I start go into my delay function, it seems that the systick interrupt does not happen anymore. It is ending in an infinite loop, but the uC is still working because, i generate an interrupt with rtc (1s) and this one is still appearing Did anyone faced a Problem like this? Here is some Codevolatile uint16_t sysTickGlobTime = 0;
void BOARD_DelayMS(volatile uint8_t ms);
void SysTick_Handler(void) {
SM_Handler();
if(++time_1ms == 2) { //1ms
time_1ms = 0;
sysTickGlobTime--;
}
}
void BOARD_DelayMS(volatile uint8_t ms) {
sysTickGlobTime = ms;
while(sysTickGlobTime!=0);
}
I'm using STM32F105RC and standart periph lib
Many thanks for help!
2015-05-22 05:12 AM
void InitDelay(void)
{
SysTick_Config(SystemCoreClock/1000);
}
/** @brief Delay
*
* @param nTime __IO int32_t
* @return void
*
*/
void Delay(__IO int32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
void SysTick_Handler(void) //Systick nvi handler
{
TimingDelay_Decrement();
}
2015-05-22 05:52 AM
And are you calling the delay function within some other interrupt?
2015-05-22 10:02 AM
One potential problem is if the test
while(sysTickGlobTime!=0);
misses the zero condition because of something else going on. What does SM_Handler() do? Are there other tasks running? If you are using a pre-emptive RTOS there's no guarantee you will catch the variable at exactly = 0x0000. A 1ms time slice will make it extremely unlikely your while loop will ever exit. If your test only sees = 0x0001 followed by =0xffff it's an effective infinite loop. Make the variable signed and check for <= 0 instead. Jack Peacock