Timer Interrupt

Saiteja chinthalapati

Joined Oct 25, 2018
97
Did anyone have idea on how to write a code to blink LED using timer delay and Timer interrupt in STM32 controller. Timer interrupt is for during delay if any other input comes the system shouldn't get hanged.

Joined Mar 10, 2018
4,057
The IDE must have an example project to blink an LED,. thats almost
universal standard feature in IDE these days.

Also they must have ap notes on configuring and handling interrupts.

Regards, Dana.

MrChips

Joined Oct 2, 2009
22,874
First step is to write code to blink an LED using software delay.

Saiteja chinthalapati

Joined Oct 25, 2018
97
First step is to write code to blink an LED using software delay.
that one i have already done

MrChips

Joined Oct 2, 2009
22,874
that one i have already done
Good.
Next step is to implement the delay by polling a flag in the timer module.

MrSoftware

Joined Oct 29, 2013
1,970
I'm not familiar with that processor, but here's some pseudo code, it's not the most efficient but should accomplish your task. You could just toggle the pin state inside your interrupt handler since changing a pin state is typically very fast, but in general you want to get in and out of an interrupt handler as quickly as possible. So this code shows how to use a flag to prevent spending too much time inside your handler, in case you decide to do more than just toggle a pin.

Code:
volatile bool LEDOn = false;

// Called when the timer expires
InterruptHandler()
{
// Toggle the LED flag
LEDOn = !LEDOn;
}

Init()
{
// Create a timer that calls InterruptHandler() every 2 seconds
CreateTimer(2_seconds, &InterruptHandler);
}

main_loop()
{
while(1)
{
if(LEDon)
SetLEDPin(high);
else
SetLEDPin(low);
// Do other stuff here, nothing is hung....
}
}

main()
{
Init();
main_loop();
}

Saiteja chinthalapati

Joined Oct 25, 2018
97
Good.
Next step is to implement the delay by polling a flag in the timer module.
I have done blinking LED using Timer delay & Software delay interrupt part i am confused how to give. i have setted the priority as 1