A nightmare with I2C serial link, especially with onReceive

@ngee
1. I2C handles data one byte at a time; accordingly, your requestEvent() function should be as follows:

void requestEvent()
{
  Wire.write(highByte(Hrs));
  Wire.write(lowByte(Hrs));
  Wire.write(highByte(Mins));
  Wire.write(lowByte(Mins));//data sent to master when requested.
}

2. At the Master side, you need to execute the following request command:

Wire.reaquestFrom(9, 4);
byte Hrh = Wire.read();
byte Hrl = Wire.read();
int Hrs = Hrh<<8|Hrl;
//---------------------------
1 Like