if I remove the transmission code from slave this works properly but I need to transmit from slave. Here is my master code
#include <Wire.h>
void setup()
{
Wire.begin(3);
Wire.onReceive(receiveEvent);
}
byte x = 0;
void loop()
{
Wire.beginTransmission(9);
Wire.write("s");
Wire.write(x);
Wire.endTransmission();
x++;
delay(500);
}
void receiveEvent(int howMany)
{
if(Wire.available()){
int x = Wire.read();
Serial.println(x);
}
}
Here is my slave code :
#include <Wire.h>
void setup()
{
Wire.begin(9); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}
void loop()
{
delay(100);
}
void receiveEvent(int howMany)
{
if(Wire.available()){
char c = Wire.read();
Serial.print(c);
if(c == 's'){
int x = Wire.read();
Serial.println(x);
//transmit to master
Wire.beginTransmission(3);
Wire.write(1);
Wire.endTransmission();
}else{
Wire.read();
}
}
}
Is it possible not to use Wire.onRequest(requestCallback); to send data to master kindly help.