I2C Padawan Seeks Jedi For Guidance

First:
Please forgive the silly subject - I couldn’t resist, despite having a serious request.

Second:
I am VERY new to the Arduino and even newer to I2C, so you’ll have to dumb it down a LOT if I’m to have a hope of understanding - so thanks in advance.

Third:
The problem - I am trying to “eavesdrop” on an I2C master by “impersonating” an I2C slave with my Arduino. I know the address of the slave, and know how to use Wire.begin(address) to join the bus as a slave with a given address. I want my Arduino to sit on the bus and echo the commands from the master to the serial port so I can see what requests it is making. Something like:

… start
… read (0x33)
… end
… start
… write (0x33) data (0xFF)

I’m sure you get the idea.

Is this even possible? The Wire library doesn’t have this kind of granularity. I looked at the TWI library and the coding in there is soooooooooooo beyond me…

I await the counsel of the Council.

Hi,
I’ve never used the Arduino as an I2C slave, but I think you want to do something like the onReceive example on the Wiring website:

#include <Wire.h> 
 
void setup() 
{ 
  Wire.begin(4);                // join i2c bus with address #4 
  Wire.onReceive(receiveEvent); // register event 
  Serial.begin(9600);           // start serial for output 
} 
 
void loop() 
{ 
  delay(100); 
} 
 
// function that executes whenever data is received from master 
// this function is registered as an event, see setup() 
void receiveEvent(int howMany) 
{ 
  while(1 < Wire.available()) // loop through all but the last 
  { 
    char c = Wire.receive(); // receive byte as a character 
    Serial.print(c);         // print the character 
  } 
  int x = Wire.receive();    // receive byte as an integer 
  Serial.println(x);         // print the integer 
}

Hope that helps!