Problem modifying variables in interrupt handler

Hello everyone,

The problem in a nutshell
I've been having a problem with variables that are manipulated inside an interrupt handler. For some reason, if I say this

volatile int a = 1
volatile int b = 2
volatile int c = 3

The variables receive the following values:

a = 3, b = 3 and c = 3

When I disable the line of c (//volatile int c = 3) the following is the result:

a = 2, b = 2 and c = N/A

Hardware and the overall functionality
My Arduino is connected to an Xbee. The Xbee returns signal strength over pin6 (RSSI). This PWM signal is leveled out to DC so that it can be send into Analogpin(0). I then use timer1 to interrupt once every second to check what value is on analog pin 0. The result is a signal strength measurement of the xbee every second.

Short introduction to the real code
I will not paste the entire code, but only the parts that I consider relevant for this problem.
The Xbee is defined in a seperate library.
The header includes the following:

class OrbXbee
{
      public:
                  OrbXbee();
            void       Setup();
            
            void      LastPacketID();
            void      GetMeters();
            void      CheckTimeOut();
            void      SendOutMessage();
                        
            volatile int            xbeeCloseNmr;                  
            volatile int            xbeeClose[];                  
            volatile int            xbeeTimestamps[];            
            volatile int            xbeeDistances[]      ;            
                        
            
      private: ....

The four variables that are declared as volatile serve to store information.
In total, there are four Xbees in my network and data about them are stored in the arrays (their name in xbeeClose, the time they were last heard in xbeeTimeStamp and their distance in xbeeDistance).
xbeeCloseNmr is simply the result of serial.read() from the xbee, since the xbees constantly send their own 'name', represented by number 0,1,2 or 3 around.

The code responsible for storing these values is:

void OrbXbee::GetMeters()
{
      LastPacketID();
      if(xbeeCloseNmr != -1)
      {
            xbeeClose[xbeeCloseNmr]             = 1;
            xbeeTimestamps[xbeeCloseNmr]       = millis();                              
            xbeeDistances[xbeeCloseNmr]            = analogRead(0);                  
            
            Serial.print("C:");
            Serial.println(xbeeClose[3]);
            Serial.print("T:");
            Serial.println(xbeeTimestamps[3]);
            Serial.print("D:");
            Serial.println(xbeeDistances[3]);

//Only checking loc 3 of the array is just temp
      }
}

When I listen for the serial output, all 3 variables received the analogRead value. When I disable the analogRead line, the top two get millis() value (like I illustrated in the top of this post).

In case it might be needed, this is the interrupt handler:

ISR(TIMER1_OVF_vect)
{
      //The interrupt fires 32 times per second but Xbee is only checked once per second (depends on pollFreq).
      
      timerOverflows++;
      if(timerOverflows > (32/pollFrequency))
      {
            OrbXbee.GetMeters();
            timerOverflows = 0;
      }
}

Cheers in advance!

This...

            volatile int            xbeeClose[];
            volatile int            xbeeTimestamps[];
            volatile int            xbeeDistances[]      ;

...does not reserve storage. You will need to provide a size for the arrays.

Your suggestion is correct.

Never could have imagined that that's where the problem laid. Would have expected an error like 'index out of bounds', although that would prob. be impossible in run-time.
Especially because I redeclared the vars in the .cpp again as followed:

volatile int xbeeCloseNmr             = 0;
volatile int xbeeClose[]             = {0,0,0,-1};
volatile int xbeeTimestamps[]      = {0,0,0,-1};
volatile int xbeeDistances[]      = {0,0,0,-1};

Anyway, your solution works.
Thanks a lot!

Index out of bounds? This is C not Java :wink:

Udo