Using multiple I2C devices via port manipulation

I´m trying to control multiple sensor devices at the same time. Hence they are all the same, they share the same I2C slave address which can´t be changed.

My Sensorboards are currently manufactured so I decided to try the communication with to I2C sensor devices which I have available.

To set this up, I already included the SoftwareWire.h from Testato ( ) so I can use multiple I2C data lines to connect multiple sensors using the same I2C slave address.

I already tested the use of 2 sensors on 2 different I2C data lines and it worked out as desired.

The question is, can I use port manipulation to trigger all sensors at the exact same time? Eventually I want to connect 8 sensorboards with 1 photodiode each. All 8 photocurrents shall be measured at the same time.

At the moment, I am only able to address my 2 connected sensors one by one. You can find my code below. Its not pretty but it works and is just for testing.

Port manipulation can be used to set the belonging pins to HIGH or LOW, but I need to write 2 hexadezimal numbers on each data line at the same time. The code I need to send at each data line looks like the following:

int gyroWriteI2C( byte regAddr, byte val){

This sends the “regAddr” and “val” through the “Wire”. I need this to be on not only one but 8 “Wires” (for example: “myWire_1”, “myWire_2” … “myWire_8”) at the same time.

Does anyone have an idea on how to implement an eight times parallel I2C communication?

I appreciate your help and suggestions.



I2C_Test.ino (17.2 KB)

Although what you're trying to do is theoretically possible (but you need the complete port B, so D0 to D7 are used, no serial communication is possible anymore), you have to write the software I2C emulation layer completely new and you won't be able to communicate with one single device but only with all together (although you can read different values from each).

I recommend to use a hardware switching device like the PCA9547 to switch between the devices very quickly. If you need faster access times use different sensors or switch to SPI which is more than 10times faster.