Skip to main content
Knowledgebase
Home
Renesas Singapore - Knowledgebase

What if the program rewrites the value of a variable but not displayed?

Latest Updated:10/28/2014

Question:

I'm using the CC-RX compiler. My program rewrites the value of a variable from an interrupt function but the variable does not reflect the new value. What do I need to do ?

Answer:

Add the volatile qualifier to declarations of external variables to which both normal and interrupt functions will refer.

 

Example
int data;    
void func(int x)   
{    
 data = x; <- The problem arises because, if a new value is to be written to a variable by an 
interrupt function after the original assignment of a value to the variable, the variable does not 
reflect the new value written by the interrupt function because the value of the variable has 
already been stored in a register and the value in the register is being used.
 ・・・    
 if(data == 0)   
 {    
  ・・・   
 }    
}     
volatile int data;
Suitable Products
CS+ (formerly CubeSuite+)
High-performance Embedded Workshop
C/C++ Compiler Package for RX Family