I'm doing a project that includes an Arduino Uno and custom hardware made by me. Everything is working perfectly independently, and I'm trying to implement a way for them (the Arduino and my hardware) to work together. In order to achieve that, I am using the Wire protocol (Arduino side) and I2C (custom hardware side). From now I can send data from my hardware to my Arduino in a master-slave relation, and I have no problem with that. Please take a look at my Arduino code for better understanding:
void setup(void) {
Wire.begin(7);
Wire.onReceive(receiveEvent);
}
void receiveEvent(int howMany) {
int x = Wire.read(); // receive byte as an integer
Serial.print(x);
if (x==0)
state = 0;
}
So far so good. Now I want to send data from the Arduino to my custom hardware full duple, and for that I am adding this code:
void frame(void){
Wire.write('x');
Wire.write('\r');
}
void loop() {
if (state == 0){
frame();
state = 1;
}
}
In order to receive the 'x' char in my custom hardware I have switched the I2C protocol bit from Write to Read using I2C_FORMAT_7_BIT_ADDRESS(SlaveAddress, _address, I2C_WRITE);
to I2C_FORMAT_7_BIT_ADDRESS(SlaveAddress, _address, I2C_READ);
in my custom hardware code.
I don't know why, I am not receiving the data from the Arduino. Am I missing any configuration on the Arduino side?