I am connecting two Arduinos over i2c protocol and trying to send from one Arduino to another 16 packets by 8 bytes and reading it with another Arduino. For some reason I am only receiving first 80 bytes.
Can any one help me how to transfer 128 or more bytes
There is my example codes:
Master Reading:
#include <Wire.h>
#include <Arduino.h>
unsigned int BEGIN = 0;
byte c[17][9];
void setup()
{
Serial.begin(9600);
Wire.begin();
//Wire.setClock(300000L);
}
void loop()
{
int address=0x55;
unsigned int j=0;
unsigned int k=0;
for (BEGIN=0x00; BEGIN<=0x78; BEGIN=BEGIN+8) // from 0 to 0x78
{
Wire.beginTransmission(address); // link to 0x50 - 0x56
Wire.write(0x80); // must act as a position pointer
Wire.write(BEGIN);
Wire.endTransmission(false);
//Wire.endTransmission();
Wire.requestFrom(address, 8); // request 8 bytes from slave
while(Wire.available()) // read from chip while avaliable
{
j++;
c[k][j] = Wire.read(); // reccive byte as byte
}
k++;
}
Wire.endTransmission();
}
Slave sending:
#include <Wire.h>
byte answer_To_80x00[]={0xE2, 0x00, 0x01, 0x0A, 0x05, 0x05, 0x00, 0x00};
byte answer_To_80x08[]={0xFF, 0x40, 0x00, 0x01, 0x20, 0x18, 0x11, 0x07};
byte answer_To_80x10[]={0x01, 0x00, 0x00, 0x98, 0x00, 0x00, 0x00, 0x00};
byte answer_To_80x18[]={0x00, 0x00, 0x00, 0x00, 0x16, 0x01, 0x20, 0x19};
byte answer_To_80x20[]={0x00, 0x00, 0x00, 0x58, 0x1B, 0x33, 0x00, 0x08};
byte answer_To_80x28[]={0x55, 0x41, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00};
byte answer_To_80x30[]={0x00, 0x00, 0x85, 0x00, 0x0A, 0xFF, 0x07, 0x08};
byte answer_To_80x38[]={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x51};
byte answer_To_80x40[]={0x00, 0x4E, 0x20, 0x00, 0x00, 0x47, 0xFD, 0x47};
byte answer_To_80x48[]={0xFD, 0x47, 0xFD, 0x02, 0x00, 0x00, 0x00, 0x00};
byte answer_To_80x50[]={0x00, 0x4D, 0x55, 0x54, 0x00, 0x00, 0x00, 0x00};
byte answer_To_80x58[]={0x00, 0x00, 0x00, 0x56, 0x00, 0x00, 0x00, 0x51};
byte answer_To_80x60[]={0x4D, 0x55, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00};
byte answer_To_80x68[]={0x49, 0x4D, 0x50, 0x50, 0x2D, 0x31, 0x38, 0x30};
byte answer_To_80x70[]={0x30, 0x30, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00};
byte answer_To_80x78[]={0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
int A8_request=0;
int x80_request=0;
int _step = 0;
void setup()
{
Wire.begin(0x55); // join i2c bus with address 55
//Wire.setClock(300000L); //300000
Wire.onReceive(receiveEvent); // register event
Wire.onRequest(sendEvent);
Serial.begin(115200); // start serial for output
}
void loop()
{
//delay(1);
//Serial.println("***********");
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while(1 < Wire.available()) // loop through all but the last
{
byte c = Wire.read(); // receive byte as a character
if (c==0x80)
{
//Serial.println(" chip reccived 0x18 ");
byte x = Wire.read();// receive byte as an integer
if (x==0x00 and x80_request==0){_step=6; /*Serial.println(" request from pointer 0x00 sending back E2");*/ x80_request=1; }
if (x==0x00 and x80_request==1 and _step==6) { _step=7;}
if (x==0x08 and x80_request==1){_step=8;}
if (x==0x10 and x80_request==1){_step=9;}
if (x==0x18 and x80_request==1){_step=10;}
if (x==0x20 and x80_request==1){_step=11;}
if (x==0x28 and x80_request==1){_step=12;}
if (x==0x30 and x80_request==1){_step=13;}
if (x==0x38 and x80_request==1){_step=14;}
if (x==0x40 and x80_request==1){_step=15;}
if (x==0x48 and _step==15){_step=16;}
if (x==0x50 and _step==16){_step=17;}
if (x==0x58 and _step==17){_step=18;}
if (x==0x60 and x80_request==1){_step=19;}
if (x==0x68 and x80_request==1){_step=20;}
if (x==0x70 and x80_request==1){_step=21;}
if (x==0x78 and x80_request==1){_step=22; x80_request=0;}
}
//Serial.println(" I reccived: ");
//Serial.print(c, HEX); // print the character
}
byte x = Wire.read();// receive byte as byte
//Serial.print(" Just reading: ");
//Serial.println(x, HEX); // print the hex
}
void sendEvent()
{
if (_step==6) {Wire.write(answer_To_80x00,8);}//{Wire.write(0xE2);}
if (_step==7) {Wire.write(answer_To_80x00,8);}
if (_step==8) {Wire.write(answer_To_80x08,8);}
if (_step==9) {Wire.write(answer_To_80x10,8);}
if (_step==10) {Wire.write(answer_To_80x18,8);}
if (_step==11) {Wire.write(answer_To_80x20,8);}
if (_step==12) {Wire.write(answer_To_80x28,8);}
if (_step==13) {Wire.write(answer_To_80x30,8);}
if (_step==14) {Wire.write(answer_To_80x38,8);}
if (_step==15) {Wire.write(answer_To_80x40,8);}
if (_step==16) {Wire.write(answer_To_80x48,8);}
if (_step==17) {Wire.write(answer_To_80x50,8);}
if (_step==18) {Wire.write(answer_To_80x58,8);}
if (_step==19) {Wire.write(answer_To_80x60,8);}
if (_step==20) {Wire.write(answer_To_80x68,8);}
if (_step==21) {Wire.write(answer_To_80x70,8);}
if (_step==22) {Wire.write(answer_To_80x78,8);}
}
There is my result which I am getting from logic analayser,
reading only first 80 bytes and it just stops:
write to 0x55 ack data: 0x80 0x00
read to 0x55 ack data: 0xE2 0x00 0x01 0x0A 0x05 0x05 0x00 0x00
write to 0x55 ack data: 0x80 0x08
read to 0x55 ack data: 0xFF 0x40 0x00 0x01 0x20 0x18 0x11 0x07
write to 0x55 ack data: 0x80 0x10
read to 0x55 ack data: 0x01 0x00 0x00 0x98 0x00 0x00 0x00 0x00
write to 0x55 ack data: 0x80 0x18
read to 0x55 ack data: 0x00 0x00 0x00 0x00 0x16 0x01 0x20 0x19
write to 0x55 ack data: 0x80 0x20
read to 0x55 ack data: 0x00 0x00 0x00 0x58 0x1B 0x33 0x00 0x08
write to 0x55 ack data: 0x80 0x28
read to 0x55 ack data: 0x55 0x41 0x00 0x08 0x00 0x00 0x00 0x00
write to 0x55 ack data: 0x80 0x30
read to 0x55 ack data: 0x00 0x00 0x85 0x00 0x0A 0xFF 0x07 0x08
write to 0x55 ack data: 0x80 0x38
read to 0x55 ack data: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x51
write to 0x55 ack data: 0x80 0x40
read to 0x55 ack data: 0x00 0x4E 0x20 0x00 0x00 0x47 0xFD 0x47
write to 0x55 ack data: 0x80 0x48
read to 0x55 ack data: 0xFD 0x47 0xFD 0x02 0x00 0x00 0x00 0x00
write to 0x55 ack