Notifications
Clear all

I2C Multiplexer/ Switch

4 Posts
4 Users
1 Reactions
114 Views
 Shar
(@shar)
Member
Joined: 1 month ago
Posts: 5
Topic starter  

There is this TCA9548 I2C Mux which can be if we have slaves with fixed and same addresses. Now suppose we connect one slave to channel1 and other to channel2. Now if the master wants to communicate with any of the slaves it will do it through the MUx. so first it will send the address of the MUX first and then select the channel through the control register. Now my doubt is that once it selects the channel...Then after channel selection will master again send the address of the slave connected to that channel( one specified by its datasheet) ? or will it directly start sending data? Because if master does not send the slave(say sensor) I2C address then how will slave send acknowledge bit? Because according to I2c specification devices on I2c bus compare the address sent by the master with their own address and then send acknowledge bit if it matches................


   
Quote
(@davee)
Member
Joined: 3 years ago
Posts: 1851
 

Hi @shar,

  I have never used the multiplexer, but I recalled the forum host Bill (@dronebot-workshop) has one of his great blog + videos on the subject, which at a quick glance seems to go a fair way to answering your question.

https://dronebotworkshop.com/multiple-i2c-bus/

I am not sure, but maybe you have a little confusion as to the order of events. Looking at a fragment of Bill's code:

 // Read temperature as Celsius
  float t = am2320.readTemperature();
  // Read Humidity
  float h = am2320.readHumidity();
  
  // Set multiplexer to channel 1 and display temperature
  TCA9548A(1);
  displayTemp(t);
  display1.display();
  
  // Set multiplexer to channel 2 and display temperature
  TCA9548A(2);
  displayHumid(h);
  display2.display();
  

Note the comment says "Set multiplexer to channel 1 and display temperature" ... that is the "TCA9548A(1);" is setting the multiplexer such that whatever follows from the controller will be sent to I2C port "1", which is connected to display showing the temperature.

Unfortunately, I suspect the second comment has suffered from a little too much 'Copy and Paste', and should read "// Set multiplexer to channel 2 and display humidity".

Remember the two displays are connected to two different pairs of outputs from the TCA chip, and the TCA chip is acting like a 'two pole, 1 to many way' switch.

The "TCA9548A(x);", where x=1 or 2, is setting the switch position. The switch position determines which of the displays is connected to the microcontroller at any one moment. Thus display2 is effectively isolated when the switch is set to 1, and vice versa..

-----------

Does that clarify the position?

Best wishes, Dave


   
Ron reacted
ReplyQuote
(@aliarifat)
Member
Joined: 1 month ago
Posts: 28
 

After selecting the channel on the TCA9548A, the master must still send the I2C address of the slave device on that channel. The multiplexer only routes the communication to the correct channel, but the standard I2C protocol still applies, meaning the slave devices need to be addressed explicitly by their I2C address.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7590
 

@aliarifat Yep, that is what multiplex means.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote