Hello,
I'm trying to use I2C to communicate between Arduino Due and Nano. I have encountered some problem in Arduino Due I2C.
#include <Wire.h>
int x = 0;
void setup() {
Wire1.begin(8); // join i2c bus with address #8
Wire1.onReceive(receiveEvent); // register event
//Wire1.onRequest(requestEvent);
Serial.begin(9600); // start serial for output
pinMode(13, OUTPUT);
}
void loop(){
Wire1.beginTransmission(9);
Wire1.write(x);
Wire1.endTransmission();
x++ ;
delay(100);
}
void receiveEvent(int howManay){
x = Wire1.read();
}
void requestEvent(int howManay){
}
This is the simple code I have written for Due as Master. The master address is '8' and Slave address is '9'. Also, I have connected to the oscilloscope to observe the communication.
- If I write the code as given in above code "Wire1.begin(8);" with the value of Master address there is no SCL or SDA can be seen on the oscilloscope. This can solve if I don't mention any value to "begin()". Also, obsereve that if Due is acted as the slave then "Wire1.write()" is not working. As my assumption, it because of the initialization of "begin()". If I pass any value to it then write is not possible. Is there any way we can specify whether it is master or slave.
- If I uncomment "Wire1.onRequest(requestEvent);" I get following errors
exit status 1
invalid conversion from 'void (*)(int)' to 'void (*)()' [-fpermissive]
I need help for these problem