A simple I2C question

I'm intending to have two microcontrollers, one master and once slave, on an I2C bus. The slave will have multiple I2C sensors and outputs connected to it and will be running a PID controller as well as managing the GUI. The master will simply issue periodic commands and requests for information while interfacing with other supervisory systems via a separate serial connection.
Are there any issues with handling it this way, where the slave is, in effect, a master of other subordinate devices?

Are you saying that you will have two microcontrollers and multiple sensors on the same I2C bus, and you want microcontroller A to instruct microcontroller B to query the sensors and then microcontroller B sends the results to microcontroller A? So microcontroller B is both a slave and a master? Maybe the I2C bus is more flexible than I give it credit for, but I can't see that working.

Now, if microcontroller B has two I2C buses and all the sensors are on one bus and microcontroller A is on the other... yeah, I can see microcontroller B being a master on one bus and a slave on the other. Hypothetically, at least.

I don't think that is possible with one I2C bus. The I2C hardware is either master or slave, and there can be only one master on a bus at any one time.

UART serial is much easier to use than I2C for processor-to-processor communication as it is inherently bidirectional, with two independent channels.

But, I2C is also bi-directional except that it is half-duplex.

Depends
Which Arduinos are you planning on using?

Yes. You need to use two separate I2C buses on the microcontroller that acts as the slave and that also controls a number of sensors. One bus will be for communication with the master microcontroller. The other bus will be for communication with the sensors etc.

Fortunately, there are plenty of microcontrollers with more than one hardware I2C bus.

I'm actually using a pair of Teensy 4.0s and I have them wired/traced to use two separate I2C busses; one for all of the sensors and DACs and the other just connecting the two MCs.

I wonder if it would be simpler to make the MC with all the peripheral stuff the master and use the MC that's communicating with the outside as the slave? It would still have to use two I2c busses (it's hardwired that way) but the coding might be a little less convoluted with only one master? Any thoughts?

Depends on your application, really. I really couldn't say. Either can work.

Given this description:

my question would mostly be why you'd need two controllers in the first place? Why not just use one that's capable of handling all of it?

What do you mean?
Is one of the I2C ports of one of the MCs hardwiared to one of the I2C ports of the other MC?

I would use SPI bus to connect the MCU's.

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