I2C - communication mulfunctioning on Arduino Mega 2560

Dear All,

I'm havig here I2C mulfuctioning on Aruino i2C Bus. The I2C bus is wired with 1 KoHM resistors. I tested it on Arduino Uno, Uno same string of devices, works without any issues. On Mega does not. When I start a I2C scanner it shows me that there are dozens of devices on Bus, but in real just 4 devices. I tried to reset, change the wires, conneced to other I2C ports but issue persists.

any idea why it shows many devices on bus while there are just 4.

any help highly appreciated

The I2C bus is wired with 1 KoHM resistors.

That's to weak even for an UNO. Use at least 2k2.

no same string of devices, works without any issues. On Mega does not.

The Mega has built-in pull-up resistors. Using 1k pull-ups in parallel make the total pull-up even smaller and the current to sink to high (out of spec).

any idea why it shows many devices on bus while there are just 4.

Maybe you already fried one of the devices and it just runs bad now?

What devices do you have on the bus?

Hi,

so string of devices starting : mcp4531(potti), then LM-75 thermal watchdog, and 2 x pcf8575 so all together 4 devices.

I'm using a Mega as an I2C slave and I'm using 4.7k pullups on my bus. Gonna agree with pylon here that 1k is likely too low.

If you're still getting a full bus reported by a scan after increasing the pullups, the next step is to disconnect all devices and do a scan. If there's still a full bus, I'd be eyeing the Mega itself as possibly having a malfunctioning I2C module. If the bus reads empty, add one device at a time and scan to see if the problem suddenly pops back up, at which point the most recently added device becomes suspect.

Is it possible that you left the address pins of the connected devices floating? That would almost explain the range of addresses the scan found.
I support the suggestion of WebMaka to start with an empty bus and add one device after the other.

update,

so far pullups changed to 9.0 Kohm, on both lines. Even with the one device on Bus, in serial monitor it shows full bus of devices. Even if I remove the i2c connection wires, it still shows full bus on devices.

Can it be related to i2s scanner program itself?

I found several ones, the one I am using is the following:



#include <Wire.h>
void setup()
{
Wire.begin();

Serial.begin(9600);
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
// Wire.endTransmission to see if
// a device acknowledged the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();

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
}

Post a wiring diagram of the setup that produced that result. Was that running on a bare Mega2560 without any device attached?

Are you using an original Arduino Mega2560 or a Chinese clone?

The TWI devices are working with the UNO, but they are not working with Mega. Arduino Mega is being suspected to contain a malfunctioning TWI Interface. The execution of the following codes may reveal if the TWI Interface is really bad! We assume that the Arduino Mega contains built-in pull-up for the TWI Bus and all TWI devices are disconnected from the TWI Bus. (These codes work for the UNO.)

void setup() 
{
  
  pinMode(13, OUTPUT);
  Serial.begin(9600);
  TWBR = 0x02;
  TWSR = 0x02;     //200 KHz speed

  TWCR = 0b10100100;
  while (bitRead(TWCR, 7) !=HIGH)
    ;
  Serial.print((TWSR & 0b11111000), HEX); //shows status code: 0x08

}

void loop() 
{
  digitalWrite(13, !digitalRead(13));
  delay(2000);

}

Having received the status code (0x08), we may proceed to receive the next status code (0x18) by connecting only the mcp4531 in the bus and issuing the following commands (untested):

START command    //correct status code: 0x08
(codes are similar to above)

//deviceaddress inquiry in Write Mode        correct status code: 0x18
//codes to be executed are: 
TWDR = 0bXXXXXXX0;          //XXXXXXX are 7-bit Pot address
TWCR = 0b10000100;            //needed to generate clock pulses
while(bitRead(TWCR, 7) !=HIGH);
   ;
Serial.print((TWSR & 0b11111000), HEX);     //Serial Monitor should show: 0x18

STOP command
TWCR = 0b10010100;

I use the Wire library with my Mega 2560, and it works ok.

We assume that the Arduino Mega contains built-in pull-up for the TWI Bus

We don't assume it, we know it. The schematic shows it clearly.

and all TWI devices are disconnected from the TWI Bus.

Please explain how that relates to the pull-ups.

Arduino Mega is being suspected to contain a malfunctioning TWI Interface.

I never heard of that and my Mega2560 works without any problems.

Yes! The Mega Board contains pull-up resistors for the TWI Bus.

Some TWI devices/breakout-boards (like BMP180) contain built-in pull-ups, and when those devices are connected with the Mega, the resultant pull-up will be different.

Post#3 was suspecting a malfunctioning I2C module to which I had simply referred with my broken English.