I2C1 access ?

I could use some help trying to utilize I2C1 port.
I found a snippet of code which indicates to use Wire1.xxx but I cannot find it in Wire.h source ( last updated 2012).
I am using a simple I2C scanner and it returns no devices connected.

// The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire1.beginTransmission(address);
    error = Wire1.endTransmission();

I am sure the I2C1 port has to be addressed / identified somehow and Wire1.xxx just does not do it.
My next step is to look thru SAM datasheets for some hint.
Google is not much help.
Any suggestions on how to address the I2C1 port would be appreciated.

Cheers Vaclav

Vaclav,

I've used an MPR121 capacitive touch sensor on the second TWI port. Below is some code extracted from a much larger sketch. The Due doesn't have on-board pullups for the second Wire port, so be sure your device has them.

Jon

#include <Wire.h>  //for touch sensors
boolean mpr121Present1 = 1;  //second mpr121 captouch presence flag

void setup() {

  Serial.begin(115200);
  Wire1.begin();

  Wire1.beginTransmission(0x5a);          //test for MPR121 on second TWI port
  word error = Wire1.endTransmission();

  if (error == 0)  {
    mpr121Present1 = 0;
    Serial.println("MPR121 1 found");
    //call MPR121 initialization function here
  }
  else  {
    Serial.println("MPR121 1 not found");
  }

}

void loop() {

  //Your loop() code, including calls to readTouchInputs1()

}


void readTouchInputs1()  {
  //read the touch state from the second MPR121
  Wire1.beginTransmission(0x5a);
  Wire1.requestFrom(0x5A,2);

  byte LSB = Wire1.read();
  byte MSB = Wire1.read();

  Wire1.endTransmission();

  uint16_t touched = ((MSB << 8) | LSB); //16bits that make up the touch states
  if (touched)  {
    Serial.println(touched, BIN);
  }
}

The pin definition for Wire1 is defined in Wire (.h,.cpp) and variant (.h,.cpp).

You can connect Wire and Wire1 for echo test but remember to use pull-ups (4.7K) in second I2C as stratosfear said.

p

Palliser:
The pin definition for Wire1 is defined in Wire (.h,.cpp) and variant (.h,.cpp).

You can connect Wire and Wire1 for echo test but remember to use pull-ups (4.7K) in second I2C as stratosfear said.

p

Palliser:
The pin definition for Wire1 is defined in Wire (.h,.cpp) and variant (.h,.cpp).

You can connect Wire and Wire1 for echo test but remember to use pull-ups (4.7K) in second I2C as stratosfear said.

p

I MUST be looking at wrong wire.h/cpp. Can you send me a link, please?

I just found ATmel Software Framework sample codes for TWI. But the LCD is low priority and I may just skip coding on register level for now.

I have moved to the TWI 1 ( pins 20.21) and still cannot get anything from the scanner.
I guess I should put a scope on the pins to make sure. Fun.
I sure wish people who publish their code did better to provide feedback - functions returning something - so one does have clue if the hardware is REALLY connected.

Cheers Vaclav

Here a Due I2C/I2C1 pin interconnection diagram and echo sketch using both I2C in the same Due.
It works OK (IDE 1.5.7).

#include <Wire.h>

void setup()
{
  Serial.begin(9600);           // start serial for output
  Wire1.begin(4);                // join i2c bus with address #4
  Wire1.onReceive(receiveEvent); // register event
  Wire.begin(); // join i2c bus (address optional for master)
}

byte x = 0;

void loop()
{
  Wire.beginTransmission(4); // transmit to device #4
  Wire.write("x is ");        // sends five bytes
  Wire.write(x);              // sends one byte  
  Wire.endTransmission();    // stop transmitting

  x++;
  delay(500);
}

void receiveEvent(int howMany)
{
  while(1 < Wire1.available()) // loop through all but the last
  {
    char c = Wire1.read(); // receive byte as a character
    Serial.print(c);         // print the character
  }
  int x = Wire1.read();    // receive byte as an integer
  Serial.println(x);         // print the integer
}

In the serial monitor (Newline, 9600, auto-scroll) you should get something like:

x is 0
x is 1
x is 2
x is 3
x is 4
...
...
x is 252
x is 253
x is 254
x is 255
x is 0
x is 1
x is 2
...
...

p

Wire files here:

...\hardware\arduino\sam\libraries\Wire

Variant files here:
...\hardware\arduino\sam\variants\arduino_due_x

Thanks guys,
got caught in my own "cut and paste " do-do. It did not include Wire.begin()!
Now the Due is reporting random number of I2C devices with only one LCM1602 module connected on pins 20 /21.
Still something fishy about the way the TWI interface in labeled on the board.
But making progress.
Been going thru the BIG datasheet and still no sure if BOTH TWI have pull-ups, but when used in "master" AKA send mode it should not matter but... TWI expect ACK so it may be important, will check that later.
I am sure it is in the datasheet, somewhere near pages 717!

The Arduino Due board has 1k pullups on the SDA and SCL lines. It does NOT have pullups on the SDA1 and SCL1 lines.

If you are connecting any I2C to SDA and SCL then you probably don't need any more pullups. (Don't connect more than 2 DUEs since too many pullups can exceed the I2C limits.

If you are connecting something to SDA1 and SCL1 then you will need to add your own pullups, or check that your something has the pullups.

The internal 'weak pullups' in the chip aren't good enough for SPI. You need something like 4.7k and this varies depending on the capacitance (length) of your SPI wires and the speed you are trying to achieve.