Qwertyqwq:
if you have any example about sending value slave to master with that comminication protocol, please share with me..
Have you wanted to say that you need an example which describes how to send a data byte from an active slave (the 2nd Arduino UNO) to master (the first Arduino UNO) using I2C Bus? If so, these are the clues which you must frame within the setup() and loop() functions of the IDEs of both Master and Slave to come up with a working program (s).

1. Assume the 7-bit slave address is given by the symbolic name : slaveAddress.
2. Now, tell the Master to check that the Slave is present. The codes are;
Wire.beginTransmission(slaveAddress);
busStatus = Wire.endTransmission()
if (busStatus != 0x00)
{
Serial.print("Slave is not present...!");
while(1); //wait for ever
}
3. Tell the Master to command (arbitrary command code is 0x14) the Slave to keep one byte data (say, 0x23) in its buffer from which the Master will read it later. The codes are:
Wire.beginTransmission(slaveAddress);
Wire.write(0x14); //0x14 is the arbitrary command code for the Slave.
Wire.endTransmission()
4. Once the code 0x14 of Step-3 goes to the Slave (the 2nd UNO), the slave will be immediately interrupted and will go to the following routine and will read the arrived data byte. If the arrived data byte is really 0x14, it will set a flag.
void receiveEvent(int howmany)
{
byte x = Wire.read();
if (x == 0x14)
{
bool flag = HIGH;
}
else
{
;
}
}
5. For the Slave to execute the routine of Step-4. the following declaration must be included in the setup() function of the Slave.
Wire.onReceive(receiveEvent);
6. Tell the Master to issue 'data read request" command to the Slave for reading 1-byte data which is already present in the loca buffer of the Slave. The codes are:
Wire.requestFrom(slaveAddress, 1);
7. After the execution of the above command, the Slave is immediately interrupted. The Slave goes to the following routine and writes the data byte (0x23) (after checking flag status) into its local buffer. The codes are:
void sendEvent(int howmany)
{
if(flag == HIGH)
{
Wire.write(0x23);
}
else
{
;
}
}
8. For the Slave to execute the routine of Step-7, the following declaration must be included in the setup() function of the Slave.
Wire.onRequest(sendEvent);
9. After the execution of the instruction of Step-6 and 7, the data (0x23) from the local buffer of the Slave comes into the local buffer of the Master. Now, tell the Master to read the data byte (0x23) from its local buffer and show on the Serial Monitor. The codes are:
byte y = Wire.read();
Serial.println(y, HEX);
