I2C troubles to send, receive data

Hello team,

I have a question related to I2C.
Actually I have connected 2 arduinos (One as Master and the another one as Slave), both are connected with the corresponding PINS: SCL and SDA.
o.
The problem is:

actually when I upload the programs to each Arduino, I only receive the adress, but the data is missing in Master and in Slave too. I attached the screenshot "Missing info" where is the answer.

and before I could see them but now it doesn't appear anymore.
I tried to re-upload the code but the signal answer always is the same
Please let me know if it's more a trouble with my programm or something more. or if you know some tip that could help me.

I attached the code if you need to review it for Master and Slave

MASTER

#include<Wire.h>
void setup() {
  Wire.begin();  
}
void loop() {
  Wire.beginTransmission(0X35); // transmit to device #35    
  Wire.write(0x11);      
  Wire.write(0x85);
  Wire.write(0x34);    
   Wire.write(0x00); 
   delay(1);     
  Wire.endTransmission();    // stop  transmitting

Wire.requestFrom(0x35,8);
}
#include <Wire.h>

bool S = true;
const int RP6= 6;
const int RP7= 7;
const int RP8= 8;
const int RP9= 9;
int P6= 0;
int P7= 0;
int P8= 0;
int P9= 0;
 int Reception;
 int Rep1;
 int Rep2;
 int Rep3;

void setup() {
  Wire.begin(0x35);                // To connect i2c bus with the adress #35
  Wire.onRequest(eventoSolicitud); // Register data event request
  Wire.onReceive(eventoRecepcion); // Register data event receive
  Serial.begin(9600);
  pinMode(RP6, INPUT);
  pinMode(RP7, INPUT);
  pinMode(RP8, INPUT);
  pinMode(RP9, INPUT);
  
}
 
 
void loop() {
  P6=digitalRead(RP6);
  P7=digitalRead(RP7);
  P8=digitalRead(RP8);
  P9=digitalRead(RP9);
  delay(500);
}

void eventoRecepcion(){ 
 
  Reception= Wire.read();
  Rep1= Wire.read();
  Rep2= Wire.read();
  Rep3= Wire.read();
  
       if( Reception== "11" && Rep1=="85" && Rep2=="34" && Rep3=="0")
       {
        S = false;    
       }
      
     Serial.print(Reception,HEX);
     Serial.print(Rep1,HEX);
     Serial.print(Rep2,HEX);
     Serial.print(Rep3,HEX);


}

 
// function that executes whenever data is requested by master
void eventoSolicitud() {

  if( S == true ){
   /* Wire.write(0xFF);
    Wire.write(0xFF);
    Wire.write(0xFF);
    Wire.write(0xFF);
    Wire.write(0xFF);
   */
  
  }
   else if(P6==0 && P7==0 && P8==0 && P9==0){
  
    Wire.write(0x80);
    Wire.write(0x0B);
    Wire.write(0xFC);
    Wire.write(0x01);
    Wire.write(0x4A);
    Wire.write(0x51);
    Wire.write(0x8D);
    Wire.write(0x4F);       
  }
   else if(P6==0 && P7==0 && P8==1 && P9==0){
    
    Wire.write(0x80);
    Wire.write(0x09);
    Wire.write(0x02);
    Wire.write(0x00);
    Wire.write(0x49);
    Wire.write(0x51);
    Wire.write(0x8D);
    Wire.write(0x4F);
       }    
      
}

Thank you so much.


You must not call any interrupt-dependent code (p.e. methods of the Serial object) inside interrupt context! Both Wire event callbacks are called in interrupt context. Your code may lead to a freeze.

Remove that line, it's contra-productive.

You should print out the return values of Wire.endTransmission() and Wire.requestFrom() on the master. That shows if the transfer was successful.

Reception= Wire.read();
  Rep1= Wire.read();
  Rep2= Wire.read();
  Rep3= Wire.read();
  
 if( Reception== "11" && Rep1=="85" && Rep2=="34" && Rep3=="0")

The string literals are not going to have the byte values you are looking for.

Try
if( Reception== 0x11 && Rep1== 0x85 && Rep2== 0x34 && Rep3== 0x00)

based on this

 Wire.write(0x11);      
 Wire.write(0x85);
 Wire.write(0x34);    
  Wire.write(0x00);
1 Like

Ok, I'll delete Serial print and delay too.

Something is wrong with the scope image, but I don't understand what I see in the picture.
The data from the Master is there, but the data from the Slave seems a little like it, but many bits are missing.

Which Arduino boards do you use ?
The most important wire of the I2C bus is the GND wire. Did you connect the GNDs ?
Do you have pullup resistors ?
How long are the wires ? What kind of wires do you use ? (SDA next to SCL in a flat ribbon cable is the worst).
Does the scope misinterpret the signals ? I think it does.

If you want to test the I2C bus, then you should not use the "RP" inputs. Just send a number of bytes, and let it run for while and check if it runs for hours without any error. The I2C bus is not fault tolerant, it should work 100% all the time.

mmm I tried to run again but the signal is the same :smiling_face_with_tear:

yeah I was checking but actually is not posible to review this part yet, because the signal have not been showed yet, when I run program

Hello, yeah, there are a lot of bites missing.

Master (Arduino Giga), Slave (Arduino UNO)
Yeah, in fact I have GNDs connected in common for both Arduinos.
Yes, I have Pull ups since it helped me to have the signals in rectangle form and less peaks when I review Oscilloscope.
The wires are not long, they are short to avoid to have noises during communication. They are not flat ribbon, I'm using a cable that is able to insert in the pins for SCL and SDA, I don't know how explained.}

It shouldn't misinterpret signal, please tell me how can I review that?
RP inputs? I don't understand what it means, what is that? tell me please.
WIN_20230413_14_09_50_Pro

I see no GND wire between the boards. Do they have a common GND somewhere far away where the USB cables are plugged into a computer ? That is not good enough.

Can you show a screendump of a single byte that goes wrong ? That are 9 CLK pulses with a missing ACK on the 9th pulse.

The Arduino Giga has a STM32 processor at 3.3V.
The Arduino Uno has a AVR microcontroller at 5V. According to its datasheet, it needs at least 3.5V at SDA and SCL to see it as a high level. So officially it can not work within the specifications of the datasheet. In real life it works, but there is no noise margin left.
You could fix it with a I2C level shifter.

What is your project about ? If you need more digital or analog pins, then there are better solutions.

[ADDED]
Do you know if a Giga board as Master via a I2C level shifter to a Uno as Slave will work at all ? This is the I2C bus. You can use it with sensors. For anything else you could be in the dark.

If you don't explicitly tell otherwise we always expect you to use UNO boards!
The Giga and UNO boards use different voltages. You need level converters to adapt the two voltages. Theoretically you can get that running if the pullups are to 3.3V but don't expect such a setup to work reliably.

Hello team, I reviewed and I decided to change the Arduinos for two new ones (Arduino Mega (Master) and Arduino UNO (Slave)) and the communication was successful by using the same programm.

I disconnect and tried to connect the originals but the answer never changed. it's posible that the arduinos received high voltage or current and it was not posible to get the communication again.

Thaank you so much

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