Hello I’m trying to use the timer callback with 500ms period in my project but while debugging I can see that the callback is not entered. Here’s declaration of timer and led variable:
TimerHandle tim;
bool led_state;
Here’s initialization of the timer:
TimerHandle::Config config;
config.dir = TimerHandle::Config::CounterDir::UP;
config.enable_irq = true;
config.period = 9999;
config.periph = TimerHandle::Config::Peripheral::TIM_2;
tim.Init(config);
tim.SetPrescaler(9999);
tim.SetCallback(timerCallback, nullptr);
tim.Start();
Here’s the callback function:
void timerCallback(void* data)
{
hw.SetLed(led_state);
led_state = !led_state;
}
Thanks for any support
Welcome to Daisy Forum.
Suggestion: if you want someone to debug your code, provide code which is reduced to only the essentials demonstrating your problem.
Thx for suggestion, I’ve edited my post
I’m sorry, I wasn’t clear. I meant, code which can be compiled and debugged, as is.
Try using another timer peripheral than TIM_2
. libDaisy’s system support code already uses TIM_2
for a high resolution tick timer – anytime you call System::Delay()
or System::GetUs()
etc that’s using TIM_2
so it can’t be reused for something else.
Try using TIM_5
instead, it’s another 32-bit timer. TimerHandle
doesn’t have support for all of the timers on the STM32 and that’s the only other one libDaisy supports currently that’s 32-bit, the others are only 16-bit so you need to be more careful about how you manage the prescaler/period.
4 Likes
I tried and it works on TIM_5 huge thanks!
1 Like