I2C: 2xMega2560, 1xUNO R3

Нет ответов
Deep Sky
Offline
Зарегистрирован: 12.10.2014

подключил 3 девайса по I2C. 

Master(ADR:1, PIN-20:SDA, PIN-21:SCL, GND) без какого резистора.

Slave1(ADR:2, PIN-20:SDA, PIN-21:SCL, GND)

Slave2(ADR:3, PIN-4:SDA, PIN-5:SCL, GND)

2 Мега общается и понимают друг друга. как только включаю UNO по I2C связь перерывается и ни что не общается.

вот код для Slave2-UNO:

#include <Wire.h>

///SLAVE Sender///

void setup()
{
  Serial.begin(9600);
  Wire.begin(3);                // join i2c bus with address #2
  Wire.onRequest(requestEvent); // register event
}

void loop()
{
  Wire.requestFrom(1, 20);    // request 6 bytes from slave device #1      ///Receiving from Master ID1; Mega2560///

  while(Wire.available())    // slave may send less than requested
  { 
    char c = Wire.read(); // receive a byte as character
    Serial.print(c);         // print the character
  }
  delay(500);
}

void requestEvent()
{
  Wire.write("Hello my dear0000000 "); // respond with message of 6 bytes         ///Sending to Master ID1; Mega2560///
                       // as expected by master
}

и вот код Мастера Mega 2560:

#include <Wire.h>
///MASTER Receiver///

boolean in = LOW;
void setup()
{
  Wire.begin(1);        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
  Wire.onRequest(requestEvent);
}

void loop()
{
  Wire.requestFrom(2, 20);    // request 6 bytes from slave device #2   ////Receiving Slave ID2; Mega2560////

  while(Wire.available())    // slave may send less than requested
  { 
    char c = Wire.read(); // receive a byte as character
    Serial.print(c);         // print the character
  }
  delay(500);
  
  Wire.requestFrom(3, 20);                                              ///Receiving Slave ID3; Uno R3///
   while(Wire.available())    // slave may send less than requested
  { 
    char d = Wire.read(); // receive a byte as character
    Serial.print(d);         // print the character
  }
  delay(500);
  
}
void requestEvent()
{
  Wire.write("Amigo go home to fap "); // respond with message of 6 bytes           ///Sending///
                       // as expected by master
}

что здесь не так? как мне исправит общению