I2C => Impossilbe to take 4 bytes in mode Master Reader

Hello,

In first all my apologies to my English.

Now I'm developping an apllication to use five ARDUINO UNO. I chose I2C communication between their.

I can't in Master Reader, recieve serval bytes.

CODE MASTER

void setup(){
    Wire.begin(0); // le Maitre est sur l'adresse #0
}

void loop(){
  Wire.requestFrom(slave, 4);
  s_DAT1 = Wire.read();

  s_DAT2 = Wire.read();

  s_DAT3 = Wire.read();

  s_DAT4 = Wire.read();

}

CODE SLAVE

void setup(){
    Wire.begin(slave);
    Wire.onRequest(Transmission_I2C);
}

void loop(){

}     

void Transmission_I2C(){
    Wire.write(DATA1);
    Wire.write(DATA2);
    Wire.write(DATA3);
    Wire.write(DATA4);
}

This programmes put DATA4 (slave data) in s_DAT1 (Master data).

My aim is to recieve DATA1 in s_DAT1, DATA2 in s_DAT2...

Have you one solution for me?

Thanks

Look at the master reader and slave sender examples that come with the wire library. Your problem is probably not checking for returned data first. Wrap the reading part in while(Wire.available()) to ensure data is ready before trying to read it.

Probleme is solved.

I sended 4 x 1 byte with my Slave than my Master needed 1 x 4 bytes.

the new code into the SLAVE is:

SLAVE:

void setup(){
    Wire.begin(slave);
    Wire.onRequest(Transmission_I2C);
}

void loop(){

}     

void Transmission_I2C(){
unsigned char donnees[]={DATA1,DATA2,DATA3,DATA4};
    Wire.write(donnees,4);
}

Now my fonction is ready.

Thanks