I2C problem in Arduino Due

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.

  1. 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.
  2. 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

I have encountered some problem in Arduino Due I2C.

Is the Arduino Due communicating with the PC using I2C? If not, this is CLEARLY the wrong place for your post.

There IS a Due section of the forum that clearly would be more appropriate.

From what you say you are using the second I2C port on the DUE, which will need pull up resistors installed.
I2C port 1 on the DUE has pull up resistors installed on the main board, but not for port 2.

If you do not have these pull up resistors then you will not see any data on the I2C bus with your oscilloscope.


Paul - VK7KPA

yes, I have used the pull-up register for the SDA1 and SCL1.