Another I2C Thread

Hi Guy,

I know there are several post about using the I2C bus on the DUE however; there doesn't seem to be a clear answer...

Has anyone managed to get any I2C device to work on the DUE yet?

After much weeping and gnashing of teeth, I got the newer RTC library working on my Due.

  1. The newer RTC lib uses these defines to force operation of the I2C bus to the alternate I2C pins (place in void setup() )
    #ifdef AVR
    Wire.begin();
    #else
    Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
    #endif

  2. The alternate I2C pins SCL1, and SDA1, have no hardware pull ups on the board (at least they are not indicated on the schematic). I am using 2 external 1K5 resistors on the lines.

  3. I noticed that, unlike my other projects on MEGA with RTC library, for some reason I have to read all the now.date(), now.month(0 etc variables into global variables to be able to get the data in functions and subroutines. So I wrote a sub that reads the values, and stores them in global variables of the proper type.
    If anyone is interested I can post some of the (dont laugh, I'm a newbie) code.

Hi mgirton,

What a coincidence because I'm trying to do the same thing i.e. read temperature from a RTC DS3232.

I prefer to use the Arduino default Wire library - gives me more appreciation on the mechanics of it all.

The unit I'm using has built in 10K resistors and I think that's where I'm coming unstuck. I will remove the bridge that engages the pull-ups and plug it into SCL and SDA with the built in pull-ups and see how I go.

In interested if you what to post your code :slight_smile:

It worked thanks for the advice.

Have you ever tried communicating with the RTC and use a device that requires Serial comms at the same time?

i don't like it for some reason. The data coming in from the Serial take dominates and return nothing for the I2C device.

Yes, I use a Fluxamasynth MIDI board on Com 2 of the arduino Due. I also did on the MEGA.
The RTC LIB I use for the DUE talks nicely to the ChronoDot (DS3231)
Here is a listing of the read and write functions I use for an I2C 24LC256 EEPROM I have on the same I2C bus
It uses Wire directly (note the Wire1 designation, because it is on the alternate bus,same as the clock chip)
EEPROM uses the device address of 0x50 for the EEPROM, the clock uses 0X68

void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data ) {
Wire1.beginTransmission(deviceaddress);
Wire1.write((eeaddress >> 8)); // MSB
Wire1.write((eeaddress & 0xFF)); // LSB
Wire1.write(data);
Wire1.endTransmission();

delay(5); // delay for eeprom write time
}
//-----------------------------------------
byte readEEPROM(int deviceaddress, unsigned int eeaddress ) {
byte rdata = 0xFF;
Wire1.beginTransmission(deviceaddress);
Wire1.write((eeaddress >> 8)); // MSB
Wire1.write((eeaddress & 0xFF)); // LSB
Wire1.endTransmission();
Wire1.requestFrom(deviceaddress,1);
if (Wire1.available()) rdata = Wire1.read();
return rdata;
}

mgirton,

would you be able to post your library you used?

Thanks!

adamatcooranbong:
Hi Guy,

I know there are several post about using the I2C bus on the DUE however; there doesn't seem to be a clear answer...

Has anyone managed to get any I2C device to work on the DUE yet?

Hello adamatcooranbong,

Above all, I am very happy you mentioned the I2C and Due. You are rigth about certain confusion about re-conciliate them. Indeed, I was encouraged by some friends to start a new post here trying to present a simple method about how to interconnect Due with some I2C device.

I take the advantage to clarify that regarding the Philips' bus, from the Arduino Due point of view, we talk about TWI (Two-wire Interface) instead of I2C. Due's microcontroller (SAM3X8E) has two TWI interfaces that are fully compatible with the I2C devices with some exceptions like: the START BYTE and Slope control and input filtering, AFAIK, are not supported by Due. Also, these two TWI buses keep the same pin names (SDA)(SCL)(SDA1)(SCL1).

Which is more important, there is a very good TWI library (around 20 functions) for Due and several examples (i.e. digital_potentiometer) that could help to understand better how Due works interfacing I2C devices. I believe it is more about to play with it.

If you have a I2C device you want to connect with Due, please, let me know about it and I believe we can make them work together. Regards!

wallacb
Which library do you want, The RTC one that I am using?

mgirton:
wallacb
Which library do you want, The RTC one that I am using?

the one you are using for the chronodot and the 24LC256 EEPROM, the project i am working on will be using both of those as well. i just ordered the hardware.

wallacecb
for the arduino RTC lib go to git hub here GitHub - adafruit/RTClib: A fork of Jeelab's fantastic RTC Arduino library
I used the wire library in Arduino 1.5.2 for the eeprom,
I used the Alternate SCL1 and SDA1 lines (pulled up with 1K5 resistors) on the DUE
The code is posted above in this thread. Just an eeprom write sub and an eeprom read sub.

wallabcb
oops, in the thread above the icons should be just the digit 8, as in "eeaddress >> 8" (which shifts the high byte down to so an 8 bit value is passes to the device, as it needs a 16 bit address)