Will it be possible to build a program using a single Mega 2560 to receive I2C from a Master device and replicate/regenerate on two different pins to the slave and vise versa from Slave back to master?
Why?
Paul__B:
Why?
I'm more inclined to ask "What?"
The import is pretty similar.
Usually an "XY Problem".
Yes.
I2C bus repeaters exist. A sniffer can be implemented by configuring the TWAM register to recognize all addresses.
30 Hours and counting.
Looking like a dead thread.
30 Hours and counting.
Eh? Time must be different where you are!
PerryBebbington:
Yes.
No.
This question is asked now and then.
The Master does often not support clock pulse stretching and if it does, then there are so many more problems.
Koepel:
No.This question is asked now and then.
The Master does often not support clock pulse stretching and if it does, then there are so many more problems.
I am sure it could be done. I am sure there will be limitations and difficulties, addressing was one I immediately thought of, I don't doubt there are others.
I am also sure of something You can not make a I2C man-in-the-middle that works in more than 1% of an existing situation.
You guys are talking like you at least understood what the OP wants to do; that's further than I got
Koepel:
I am also sure of somethingYou can not make a I2C man-in-the-middle that works in more than 1% of an existing situation.
What twinkleyan said
PerryBebbington:
Eh? Time must be different where you are!
Well, of course it is!
it was (five minutes local) after midnight and I didn't take that into account. Was definitely time for bed.
So good questions for why - we are trying to stay productive doing remote testing setup but eeprom card indicates physical connector needed and cycles run. We want to be able to change part number and cycles run which are stored and updated on eeprom without sending someone to office to change - a 2 sec process for 60 minutes of driving. Covid shutdown here in NY.
After reading responses yes looking to create man in middle - would timing be met if middle was instantaneous regenerating traffic? I would be looking at overlay program to change specific data if a specific string is seen.
Would you please use full sentences as if you are in school ? English is not my native language.
Most Arduino boards can be set as a I2C Slave with the Wire library. However, then the Wire library processes the interrupts and the Arduino sketch contains only a few functions. I think it is impossible to use that in between the Master and the EEPROM.
The Arduino onRequest handler keeps the SCL low until that function has finished. That is called clock pulse stretching. It is part of the I2C standard but I2C chips (sensors and EEPROM) don't have that, so not every Master device has implemented it.
If your Master device does not support clock pulse stretching, then it can not communicate with an Arduino running the Wire library.
If your Master device does support clock pulse stretching, then the Arduino board could emulate an EEPROM. I think there is no time to communicate with the original EEPROM. The Arduino could read the EEPROM during startup and store the data in the background to the EEPROM.
The Wire library does support clock pulse stretching, or else it would be impossible to have a I2C bus between two Arduino boards. When using just any existing device, then it probably does not support clock pulse stretching.
An other option is to read the levels of the I2C bus, copy them to other pins for an other I2C bus and vice versa (the I2C bus is bi-directional) and meanwhile try to change something. Even copying the levels of the pins to other pins is not reliable with a 16MHz Arduino board.
When the Master knows that there is an Arduino in between the Master and a EEPROM, then the Master can add delays and use the I2C communication in a different way.
In the end, the chance that it works for existing device is very low. If it was possible, then there would be a project or library that could do that and I should know about it.
Without an Arduino board and without the Arduino Wire library, using just hardware, then it is possible. There are chips that can translate the I2C address on-the-fly. It took 30 years before such a chip was made. Perhaps it takes another 30 years to be able to translate data bytes with an Arduino.
dprescott:
So good questions for why - we are trying to stay productive doing remote testing setup but eeprom card indicates physical connector needed and cycles run. We want to be able to change part number and cycles run which are stored and updated on eeprom without sending someone to office to change - a 2 sec process for 60 minutes of driving. Covid shutdown here in NY.After reading responses yes looking to create man in middle - would timing be met if middle was instantaneous regenerating traffic? I would be looking at overlay program to change specific data if a specific string is seen.
How long is your cable run? 60 minutes of driving suggests the devices are a long way apart, longer than I2C could ever hope to bridge however many regenerators you make.
PerryBebbington:
60 minutes of driving suggests the devices are a long way apart
... except on the M25, of course.
OK, so it is still an "XY Problem" and has not been properly explained.
no total length of I2C connection is few cm at most.
So when they allowed me a few hours to do some maintenance on-site - I connected Mega 2560 onto maintenance pins and I can communicate with the machine. I also set up Uno at home and can write/read to eeprom card with protocol analyzer so next is replicating with Uno. Host writes to set memory location it will read from.
The Mega 2560 is using wire library which is limited so I need more functions as I need to write payload to array in Mega 2560 memory.
I also want to build a database in Mega 2560 memory so when a write command arrives from host - I can write program to reply with specific payload.
which library should I be looking at?