I2C communication stalling

I'm having trouble putting two I2C devices on the same bus. I'm using an Arduino Nano EVERY to communicate with an MCP4725 and an Arduino MEGA. I'll post a basic program down below that will reproduce the failure. Both have unique addresses. The program seems to stall at either the 'dac.begin(0x60);' or the 'Wire.requestFrom(SLAVE_ADDRESS, 2);' whichever is first in the program. Everything works as it should if either one of the I2C devices is connected while the other isn't. Or if both are connected the MEGA needs to be powered on first before the EVERY. The opposite order stalls the program. One mistake from the schematic pictured the MCP4725's A0 line IS tied to GND. Any help finding and correcting where I've messed up or pointing me in the right direction would be greatly appreciated. Let me know if any more information might be useful. Thanks!

#include <SPI.h>
#include <Wire.h>
#include <I2C_Anything.h>
#include <Adafruit_MCP4725.h>

#define SLAVE_ADDRESS 9  //MEGA address for display

Adafruit_MCP4725 dac;
int ack = 0;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  delay(500);

  Serial.println("Requesting Display ACK");
  Wire.requestFrom(SLAVE_ADDRESS, 4, true);
  delay(100);
  Serial.println("Reading ACK");
  I2C_readAnything(ack);
  if (ack ==1){
    Serial.println("Display Success");
  } else {
    Serial.println("Display Failed");
  }
  
  Serial.println("");

  Serial.println("Checking DAC");
  dac.begin(0x60);
  Serial.println("DAC Success");
  
}

void loop() {

}

Why is the Mega on the bus, and what is it doing?

It is almost always a problem to connect a powered device to an unpowered device via I/O pins. You can destroy one or both doing so, so don't.

The MEGA is running a display using SSD1963 controller. In my main program there is a lot more going on on the EVERY and that sends data to the mega to be displayed.

I might be confused about what you're trying to tell me. The MEGA is powered externally, while the EVERY is powered by USB. The lines that are connected between them are the SDA, SCL, and GND. It's sounding like that isn't good practice, and suggestions on how to make it better?
Thanks.

Power them up simultaneously, and you should be OK. There is no good way to protect the I2C bus from the problem.

I2C was designed for chip to chip communication on a single PCB, and is a very poor choice for interprocessor communications. Communication is noise sensitive and does not tolerate long leads (more than a few cm).

I strongly recommend that you switch to UART serial for that. That way you can also protect the devices from damage if one is powered down. Use a 10K series resistor to limit current from an I/O output pin on a powered device to an input pin on an unpowered device.

Thanks for the advice. I'll look into switching to UART Serial communication. In my main program I also have the EVERY communicating to a LabView program on the PC. I'm assuming this is using UART Serial to communicate (it's done through all of the normal Serial commands) is there a way that you know of to define what the EVERY sends to the MEGA and what it sends to the PC?

The Nano Every has more that one serial port, as does the Mega. So you can have completely separate lines of serial communications.

Example: https://docs.arduino.cc/tutorials/nano-every/run-4-uart

I really appreciate your help! This is perfect. Thanks again!!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.