This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Volatile keyword

IU have a variable which can be chyanged outside the interrupt but inside the ISR it is only read. Its value don't change in it. Should it be volatile.

Parents
  • Thanks for answer.

    One more similar question:

    Suppose i have a variable which is only accessed inside ISR. So I think there no need to declare it volatile. Right???

    Also suppose if the code of ISR, I write it in function & declare the function with following statement:
    Now is there need of declaring a as volatile.

    void __isr(void)
    {
        code_of_isr();
    }
    
    
    __attribute__( ( always_inline ) ) __STATIC_INLINE code_of_isr(void)
    {
       int a;             /* a is only used here. Not outside in main or anywhere  */
       a= 10;
       //////////////////next code parts
    
    }
    

Reply
  • Thanks for answer.

    One more similar question:

    Suppose i have a variable which is only accessed inside ISR. So I think there no need to declare it volatile. Right???

    Also suppose if the code of ISR, I write it in function & declare the function with following statement:
    Now is there need of declaring a as volatile.

    void __isr(void)
    {
        code_of_isr();
    }
    
    
    __attribute__( ( always_inline ) ) __STATIC_INLINE code_of_isr(void)
    {
       int a;             /* a is only used here. Not outside in main or anywhere  */
       a= 10;
       //////////////////next code parts
    
    }
    

Children