Go Down

Topic: Arduino Due i2c issues (Read 1 time) previous topic - next topic

Bipman

Hi all

I've been using the i2c on my Due to connect to and write to an EEPROM.  Sometimes it works and sometimes it doesn't.  Running the i2c scanner shows nothing, yet if I run another day it is fine.  Looking around on the web, there are various answers concerning different versions of wire.cpp, pull-up resistors etc. etc.  I'm trying to find the definitive answer as there are various versions everywhere but no versions numbers to compare.  Can anyone point me to an up-to-date version of Wire for the DUE or where I might be going wrong.  It worked fine on the Arduino UNO and in fact if it keeps playing up I'm going to go to another controller although I'd rather not as all the code is for the Due.  Its the intermittent behaviour that's driving me mad >:(

Bipman

rockwallaby

A couple of questions:
What other devices are on the I2C interface?
What speed are you driving the interface at ?
Which IC2 interface are you using on the DUE ?
Is the EEPROM on a readily available board or did you make the board ?
What have you in the way of pull up resistors on the IC2 interface ?
And where is your code, in code tags of course, which might help answer some of the above questions ?
____________
Paul - VK7KPA
Paul - VK7KPA

Bipman

Hi and thanks for answering.

What other devices are on the I2C interface?
No other devices
What speed are you driving the interface at ?
Whatever speed the Wire library uses.  I have used the extEEPROM librarhy too with different speeds but it doesn't seem to make a difference.
Which IC2 interface are you using on the DUE ?
Pins 20&21
Is the EEPROM on a readily available board or did you make the board ?
It's on a veroboard.  The 24lc512 EEPROM is in a chip holder and I have taken it out and put it back in and have also re-soldered the chip holder just in case.  I also had issues when using breadboard too.
What have you in the way of pull up resistors on the IC2 interface ?
I'm not using any as not sure what to do here as again the answers seem to have many different views.

The Due board itself is a headerless one so any connections are soldered.  I've also got an SPI device (SD Card Reader) on the board and this is working great.  The code is the standard i2c scanner :-

Code: [Select]

 // --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    http://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>


void setup()
{
  Wire.begin();

  Serial.begin(250000);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}


void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    Serial.print("Scanning :- ");
    Serial.println(address);
   
    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }   
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan

  exit(0);
}




Hope that helps!


Bipman

avr_fred

Quote
What have you in the way of pull up resistors on the IC2 interface ?
I'm not using any as not sure what to do here as again the answers seem to have many different views.
While there are many opinions on what the value should be, I guess it wasn't clear that they (the pull-ups) must be present. The I2C bus is open drain, no pull-ups means no current source and no signal to speak of. The commonly accepted value is 4K7, this should be fine for short leads (6",15cm).

In general, the longer the leads, the higher the capacitance so these situations need lower value resistors for higher current to compensate for the higher capacitance and still have good rise and fall times of the signals. Overall, the I2C bus was designed for local, on the same board, chip to chip interface so there are definite bus length limits.

I would expect that two 4.7k pull-ups would give you a consistent address read from the scanner. When you get to the point you start pushing actual data back and forth, make sure your library accounts for the write times, which can be considerable. Best to consult the datasheet and compare to what the library provides, wait time wise, before putting important data onto the eeprom.

Go Up