I use a Arduino Duelmilanove to talk to a DS1307 RTC and to a Matrix Orbital LCD with i2c (wire library).
The i2c addresses are different for the two devices.
The RTC works fine when it is the only device connected to the i2c bus.
When the LCD and the RTC are connected to the i2c bus at the same time, the LCD works but the RTC send weird data.
I tried two connections schemas, one without any pull-up resistors and the other on with 2 2.2Kohms resistors.
The same behaviour occurs in the two schemas.
The LCD is a Matrix Orbital 20x4 with high voltage options (from 7 to 12 v).
And then test "err" for non-zero and do something like flash a LED (or print a debug message) you will know that the I2C failed. Perhaps the LCD library constantly polls the LCD or something.
It's hard to say more without putting a logic analyzer on the wires. If the clock works without the LCD connected, then possibly the LCD's "backpack" or whatever you have connected is frequently using the I2C for some purpose, thus denying the clock "space" to send its data. One thing you could do is check the error code, and discard the data if it (the error code) is non-zero. Maybe some of the time you get a good transmission.
The wires are about 30 cm long for the LCD and the RTC.
In the LCD manual, I found that "The I2C data line operates on 5 volts CMOS levels.", so it should be ok and it is since it's the RTC which does not work anymore when the LCD is connected (LCD is ok in all cases).
Note that I'm using only the wire lib.
Finally, I will give a try tonight to change the pullups and measure the voltages.
It finally works with 4,7KOhms pullups and, most important part, shorter I2C wires !!!
Glad you worked that out. After extra research I found that 4.7K was the recommended value - a lot of sites just mention "use a pull-up resistor" without going into too many details.
I also note in the Atmega spec it mentions "The number of devices that can be connected to the bus is only limited by the bus capacitance limit of 400 pF and the 7-bit slave address space." So perhaps the longer wires were introducing too much capacitance.
One common mistake I see is people using I2C with controllers and accepting the internal pull-up as being adequate for driving the bus. It just might work if the one I2C peripheral or memory part is the only thing connected to the processor and it is very close to the host. But even then many users report that they cannot get the 100kHz or 400kHz speed of the I2C bus, the might have to reduce the clock to 10kHz or even less. I2C was specified with a 4.7K pull-up for a darned good reason, and you will see that the rise times and thus speed capability of the bus only achieve optimal values when you use that pull-up.