Hi, I run across a problem about I2C communication .
When I send sevrial (at least two byte) byte datas
from slave board to main board at the same time ,the
main board only can read the first byte ,can’t receive
the rest of it .Here is the code:
main_read:
#include <Wire.h>
byte x,y;
void setup()
{
Wire.begin(1);
Serial.print(9600);
}
void loop()
{
Wire.requestFrom(1,2) ;
while(Wire.available()>0)
{
x=Wire.read();
y=Wire.read();
}
Serial.println(x);
Serial.println(y);
}
Slave_write:
#include <Wire.h>
byte a=12,b=56;
void setup()
{
Wire.begin(1);
Wire.onRequest(requestEvent);
Serial.begin(9600);
}
void loop()
{
Serial.println("Hello world !");
Serial.print(a);
Serial.print(b);
delay(100);
}
void requestEvent()
{
Wire.write(a);
Wire.write(b);
}
What’s wrong with it ? I’m confunsed about it .