Help, strange problem with i2c

I have one Uno and one Nano communicating over i2c. The strange thing is the master will read the correct data and display it if I assign a value to cellOne in my slave code ( see commented out line 28 in slave code). If I use the Value read on (A1 line 27) (prints correct value from slave on monitor). Then the reading output from the print on the master monitor is not correct.

example 1:
CellOne assigned to 500 on line 28.
Slave and master will both print 500.

example 2:
line 28 commented out on slave and uses value read by A1line 27.(set voltage to read 725)

Slave prints 725.
Master prints 855.

The difference between the two numbers increases as the voltage input increases.

I am fairly new to this and has spent hours trying to figure this out.

Thank you

slave code

//slave code on Nano


#include <Wire.h>
int cellOne;
void setup()
{
Wire.begin(54);
Serial.begin(9600);
pinMode (6, OUTPUT);//for relay
pinMode (A1, INPUT);
digitalWrite(6, HIGH);//for relay
//delay(200);
}
 
void loop()
{
delay(400);

Serial.println(cellOne);

Wire.onRequest(requestEvent);
}

void requestEvent()
{
cellOne= analogRead(A1);//this is line 27
//int cellOne = 500;//this is line 28
byte myArray[2];
 
myArray[0] = (cellOne >> 8) & 0xFF;
myArray[1] = cellOne & 0xFF;

Wire.write(myArray,2);

}

Master code

//master code on UNO

#include <Wire.h>


int cel1;
byte a1,b1;
void setup()
{
Wire.begin();
Serial.begin(9600);
}
 
void loop()
{
delay(1000);
 

Wire.requestFrom(54,2);
 
a1 = Wire.read();
b1 = Wire.read();

cel1 = a1;
cel1= cel1 << 8 | b1;
Serial.println (cel1);

}

@OP

During I2C Bus programming, we usually take care of the following directives which are not seen effective in your Slave Codes:

1. The Slave should follow the Master. In your case, the Slave is all the time printing the value of cellOne variable. The Master is requesting data at 1-sec interval, the Slave should also print data on its Serial Monitor at 1-sec interval. Therefore, comment out these code in the Slave sketch: delay() and Serial.println().

2. The Wire.onRequest(requestEvent) declaration should be made only once in the setup(). So, comment it out in the loop() and declare it in the setup().

3. Revise your Slave sketch as follows; upload both Master Codes and Slave Codes. Observe that the events of the Master and Slave are well synchronized.

//slave code on Nano


#include <Wire.h>
int cellOne;
bool flag1 = LOW;

void setup()
{
  Wire.begin(54);
  Serial.begin(9600);
  pinMode (6, OUTPUT);//for relay
  pinMode (A1, INPUT);
  digitalWrite(6, HIGH);//for relay
  Wire.onRequest(requestEvent);
  //delay(200);
}

void loop()
{
  //delay(400);

  //Serial.println(cellOne);

  //Wire.onRequest(requestEvent);
  if(flag1 == HIGH)
  {
    Serial.println(cellOne);
    flag1 = LOW;
  }
}

void requestEvent()
{
  cellOne = analogRead(A1); //this is line 27
  //int cellOne = 500;//this is line 28
  byte myArray[2];

  myArray[0] = (cellOne >> 8) & 0x00FF;
  myArray[1] = cellOne & 0x00FF;

  Wire.write(myArray, 2);
  flag1 = HIGH;

}

Thank you for your response. I tried your suggestions but unfortunately there is no change. I added the serial print on the slave just for debugging purposes . It just baffles me that it works fine when assigning the value but does not when reading the value from A1.

Well, I figured it out. All of my Arduino's are clones. I hav a couple different Nano clones. I tried the Nano as the master with another clone Nano as the slave (2 Nano's) with no change. If I use the UNO clone as the slave and the Nano as the Master all works normal. unfortunately I need the Nano's as the slaves for size. I guess I will order a original Nano and see if it works. If not I will ned to rethink the whole project.

My Post#1 has included tested/working I2C codes of the NANO-Slave. I have not posted the I2C Codes of Master-UNO as they are exactly same as your Master-UNO Codes.