Maker Pro
Maker Pro

Volatile and interrupts

Is it mandatory that a variable that i use in interrupt to copy microcontroller buffer data should be of type volatile? Because without it also my code seems to be working.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
It really depends on whether or not you want to chase down weird bugs.

Be aware though that the volatile keyword disables some optimization, so you may need to carefully consider where and when you want to get the current value.

For example if the variable conntrols the color of 100 LEDs and you set them all in a loop, you may wish to consider if you want to set the LEDs to the color as it was when the loop started, or never each LED set to the instantaneously determined color.
 
Top