Connect with us

Volatile and interrupts

Discussion in 'Microcontrollers, Programming and IoT' started by electronicsLearner77, Feb 6, 2017.

Scroll to continue with content
  1. electronicsLearner77

    electronicsLearner77

    73
    1
    Jul 2, 2015
    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.
     
  2. Bluejets

    Bluejets

    3,997
    826
    Oct 5, 2014
    Look up Arduino volatile in Google, there is a good explanation there.
     
  3. (*steve*)

    (*steve*) ¡sǝpodᴉʇuɐ ǝɥʇ ɹɐǝɥd Moderator

    25,362
    2,757
    Jan 21, 2010
    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.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-