ic2 3 arduino (master, slave-slave)

Hi
one little Question

i have one Master arduino that reads through ic2 two slaves Arduinos .

if i want to read both slave the same time , is the code bellow right ?

void readSlaves()  {

Wire.requestFrom(5,2);    // request 2 bytes from slave device #5   (Slave1)

while (Wire.available()) { // slave may send less than requested
   
char Q = Wire.read();



Wire.requestFrom(2,2);    // request 2 bytes from slave device #2   (Slave2)

                     while (Wire.available()) { // slave may send less than requested
   
                     byte F = Wire.read();  




 if(F != 0)   // reads bytes from slave2 depending i/o status sensors

 {



      while( Q == 'M' )   // reads characters from slave1 depending i/o status sensors

     {

// do this action

           }


         }
      }
   }
}

Thanks in Advance

if i want to read both slave the same time , is the code bellow right ?

No. You can not read from both slaves AT THE SAME TIME. One after the other is the only possibility.

Do NOT try to read from the second one in the middle of reading from the first one.

Now will be better ?

void readSlaves()  {

Wire.requestFrom(5,2);    // request 2 bytes from slave device #5   (Slave1)

while (Wire.available()) { // slave may send less than requested
   
char Q = Wire.read();

}

Wire.requestFrom(2,2);    // request 2 bytes from slave device #2   (Slave2)

                     while (Wire.available()) { // slave may send less than requested
   
                     byte F = Wire.read(); 


}

 if(F != 0)   // reads bytes from slave2 depending i/o status sensors

 {



      while( Q == 'M' )   // reads characters from slave1 depending i/o status sensors

     {

// do this action

           }


         }


      }

i want to make master read both slaves (first the one and second the other one) and make it do something based in both slave transmissions

is that possible?

The code must be different than the above in order to achieve this

Thanks in Advance

char Q = Wire.read();

This creates a new variable called Q and fills it with the byte read from I2C. By creating a new variable inside {} braces, it's "local" to those braces. You can't use that variable anywhere outside the braces.

So you're reading from I2C but immediately throwing the value away somewhere that you can't access it again.

Declare the variables in global scope (outside any function) or, preferably, inside the function where they're used.

Since your code uses Q elsewhere, there may be another definition of Q in the code you didn't show.

      while( Q == 'M' )   // reads characters from slave1 depending i/o status sensors

There must be more code you're not showing us because there's no way for the program to leave this loop. There's no way for Q to ever change while you're inside the loop. And the comment is wrong. It doesn't read the slave.