Hi...!!!
Following codes works fine on I2C for both way communication. Using this multimaster system can be understood on I2C.
//Sending command 4 bytes command to Payload and Receiving 60 bytes of data
#include <Wire.h>
int command[4] = {0x50, 0x46, 0x00, 0x00};
int mm = 0;
int count=0;
void setup()
{
Wire.begin(6);
Wire.onReceive(receiveEvent);
Serial.begin(9600);
}
void loop()
{
delay(20);
Wire.beginTransmission(0x05);
Wire.write(command[mm]);
delay(70);
mm++;
if(mm==4)
{mm = 0;}
Wire.endTransmission();
}
void receiveEvent(int howMany)
{
while(1 < Wire.available())
{ }
int x = Wire.read();
count++; if(count == 60){count = 0; Serial.println(' ');}
Serial.print(x, HEX);
}
//Output
56789ABFFC2D45B789ABF1123456789ABF212345AA789FFBF3123456789ABFF123
456789ABFFC2D45B789ABF1123456789ABF21234AA789FFBF3123456789ABFF1234
56789ABFFC2D45B789ABF1123456789ABF212345AA789FFBF3123456789ABFF1234
56789ABFFC2D45B789ABF1123456789ABF212345AA789FFBF3123456789ABFF1234
56789ABFFC2D45B789ABF1123456789ABF212345AA789FFBF3123456789ABFF1234
56789ABFFC2D45B789ABF1123456789ABF212345AA789FFBF3123456789ABFF1234
56789ABFFC2D45B789ABF1123456789ABF2123
//Payload Camera Receiving 4 bytes of command and sending 60 bytes of data
#include <Wire.h>
int mm=0;
int outgoingByte[60] = {0xFF,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0xff,0x0c,0x02,0x0d,
0x04,0x05,0x0b,0x07,0x08,0x09,0x0A,0x0B,0xF1,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0xF2,
0x01,0x02,0x03,0x04,0x05,0xAA,0x07,0x08,0x09,0xFF,0x0B,0xF3,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B};
void setup()
{Wire.begin(0x05);
Serial.begin(9600);
Wire.onReceive(receiveEvent);
}
void loop()
{int rtrn;
//For payload camera
Wire.beginTransmission(6);
Wire.write(outgoingByte[mm]);
mm++;
if(mm==60)
{
mm = 0;
}
delay(100);
rtrn = Wire.endTransmission();
delay(100);}
void receiveEvent(int howMany)
{while(1 <Wire.available())
{}
int ch = Wire.read();
Serial.println(ch, HEX);}
//Output
46
0
0
50
46
0
0
50
46
0
0
50
46
0
0
50
46
0
0
50
46
0
0
50
46
0
0
50
46
0
0
50
46
0
0
50
46
0
0
50
46
0
0
50
46
This code is working fine for my I2C implementation.
Sending command 4 bytes command to Payload and Receiving 60 bytes of data.docx (171 KB)