Hi everybody,
Sorry to disturb you, I just have a simple question about I2C; Why theses "for" loops doesn't work with I2C ?
As you will understand I want to send RFID code through I2C, it's working but my code would be nicer without all this lines :
For slave :
This is working :
void requestEvent()
{
byte buf [15];
buf [0] = hi;
buf [1] = lo;
buf [2] = codeRfidreadytosend[0];
buf [3] = codeRfidreadytosend[1];
buf [4] = codeRfidreadytosend[2];
buf [5] = codeRfidreadytosend[3];
buf [6] = codeRfidreadytosend[4];
buf [7] = codeRfidreadytosend[5];
buf [8] = codeRfidreadytosend[6];
buf [9] = codeRfidreadytosend[7];
buf [10] = codeRfidreadytosend[8];
buf [11] = codeRfidreadytosend[9];
buf [12] = codeRfidreadytosend[10];
buf [13] = codeRfidreadytosend[11];
buf [14] = codeRfidreadytosend[12];
Wire.send(buf, sizeof buf);
}
This is not working :
void requestEvent()
{
byte buf [15];
buf [0] = hi;
buf [1] = lo;
for (int x=0; x=12; x++) {
buf [x+2] = codeRfidreadytosend[x];
}
Wire.send(buf, sizeof buf);
}
For master :
This is working :
char codeRfid[12]; //at the begining of the void loop
if(Wire.available() >= 15)
{
hiByte = Wire.receive();
loByte = Wire.receive();
codeRfid[0] = Wire.receive();
codeRfid[1] = Wire.receive();
codeRfid[2] = Wire.receive();
codeRfid[3] = Wire.receive();
codeRfid[4] = Wire.receive();
codeRfid[5] = Wire.receive();
codeRfid[6] = Wire.receive();
codeRfid[7] = Wire.receive();
codeRfid[8] = Wire.receive();
codeRfid[9] = Wire.receive();
codeRfid[10] = Wire.receive();
codeRfid[11] = Wire.receive();
codeRfid[12] = Wire.receive();
}
This is not working :
char codeRfid[12]; //at the begining of the void loop
if(Wire.available() >= 15)
{
hiByte = Wire.receive();
loByte = Wire.receive();
for (int x=0; x=12; x++) {
codeRfid[x] = Wire.receive();
}
}
Thanks in advance for your help