Maker Pro
Maker Pro

Volatile and interrupts

electronicsLearner77

Jul 2, 2015
306
Joined
Jul 2, 2015
Messages
306
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.
 

Bluejets

Oct 5, 2014
6,901
Joined
Oct 5, 2014
Messages
6,901
Look up Arduino volatile in Google, there is a good explanation there.
 

(*steve*)

¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd
Moderator
Jan 21, 2010
25,510
Joined
Jan 21, 2010
Messages
25,510
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