Pages: [1]   Go Down
Author Topic: Another I2C Thread  (Read 1642 times)
0 Members and 1 Guest are viewing this topic.
Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Due the data logging machine
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Maryland
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Due the data logging machine
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley
Logged

Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 45
Due the data logging machine
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Maryland
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 >> smiley-cool);   // 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 >> smiley-cool);   // MSB
  Wire1.write((eeaddress & 0xFF)); // LSB
  Wire1.endTransmission();
  Wire1.requestFrom(deviceaddress,1);
  if (Wire1.available()) rdata = Wire1.read();
  return rdata;
}
Logged

Offline Offline
Full Member
***
Karma: 4
Posts: 107
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

mgirton,

would you be able to post your library you used?

Thanks!
Logged

Venezuela
Offline Offline
Sr. Member
****
Karma: 14
Posts: 475
Ground.......ground........always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Maryland
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Full Member
***
Karma: 4
Posts: 107
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Maryland
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

wallacecb
for the arduino RTC lib go to git hub here  https://github.com/adafruit/RTClib
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.

Logged

Maryland
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Logged

Pages: [1]   Go Up
Jump to: