Dear Arduino Community,
I have a problem with the wire library of Arduino.
I tried to implement a two-way communication without the request function,
because I had a problem with the interrupt in requestFrom.
But this does not work. It seems that the messages never arrives, or to be more precise:
receiveI2C was never called, on both sides.
MKR 1010 program:
#include <Wire.h>
#define I2C_ADDRESS_OTHER 0x1
#define I2C_ADDRESS_ME 0x2
void setup() {
Serial.begin(9600);
Serial.println("MKR");
Wire.begin(I2C_ADDRESS_ME);
Wire.onReceive(receiveI2C);
}
void loop() {
delay(5000);
Serial.println("MKR");
Wire.beginTransmission(I2C_ADDRESS_OTHER);
Wire.write("hello world from 0x2 to 0x1");
Wire.endTransmission();
}
void receiveI2C(int howMany) {
while (Wire.available() > 0) {
char c = Wire.read();
Serial.print(c);
}
Serial.println();
}
Uno program:
#include <Wire.h>
#define I2C_ADDRESS_OTHER 0x2
#define I2C_ADDRESS_ME 0x1
void setup() {
Serial.begin(9600);
Serial.println("Uno");
Wire.begin(I2C_ADDRESS_ME);
Wire.onReceive(receiveI2C);
}
void loop() {
delay(5000);
Wire.beginTransmission(I2C_ADDRESS_OTHER);
Wire.write("hello world from 0x1 to 0x2");
Wire.endTransmission();
}
void receiveI2C(int howMany) {
while (Wire.available() > 0) {
char c = Wire.read();
Serial.print(c);
}
Serial.println();
}
But the samples on arduino.cc works perfectly, but they use the request function and I don't want to use them!
If anyone asks, SDA and SCL are properly connected.