TCA9548a

Hello I was wondering if I could get some help with the TCA9548a. I was trying to use it to connect multiple slaves and have a master TCA9548a which has the A0 pin pulled high for an address change. It is just I need to make a scanner that scans for the other TCA9458a and then scans for I2c addresses on those busses. Help please!

Do you know how the TCA9548 works?

The code varies, depending on how you connect the two chips. In either case it's a modification of the I2C sniffer.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html

Have you googled tca9548a arduino

Thanks.. Tom... :slight_smile:

Yea I've been doing a lot of research everywhere. I actually have been getting a lot of help from the adafruit admin. You can find a link to that post here:
https://forums.adafruit.com/viewtopic.php?f=8&t=136752&start=30
I'm about to change my pin connections to those as suggested by the admin to connect all the SDA and SCL lines together. He has been helping me a lot and we have been debugging my project.

Why do you think you need the TCA9548.
Multiple slaves can all have their own I2C address, and can be connected to the same two I2C bus pins.
Multiple MPU9250 can be connected to the same I2C bus, with their CS pin changed 'on the fly' by a digital pin.
Tell us what you're really trying to do.

And why the cross-posts.

https://forum.arduino.cc/index.php?topic=550359.0
https://forum.arduino.cc/index.php?topic=544584.0

Leo..

Oh I don't know. I was just experimenting. I didn't know that you could just wire mpu9250s together and still get a fast data read from them. I don't even know that much about arduino in the first place. In fact I am pretty new to all this so I ended up trying to find some help across the web. I tried to delete those posts and it is mainly because no one replied. Either way I don't think what arduino I chose really matters. Nor do my project specifictions I just want to make it work so I can work on other things. I really just want to make mocap.

You can only read one sensor at the time, no matter how you connect it.

No one replied, because you didn't provide the information required to help you.
Read the forum rules.

Did you already Google something like "Arduino multiple MPU9250".
Leo..

Basically so far I have tried wiring it two ways...

Method #1

With all the SCL SDA line wired together sent to the arduino

the other...

Method #2

Having a master TCA with A0 pulled high and having the others connected to SC0 SD0 and SC1 SD1

Method #1 didn't seem like the solution as it didn't register the separate ports on master bus along with it registering the two 0x70 addresses on all ports.

Method #2 worked with it scanning all the ports and also registering two different 0x70 addresses on seperate ports.

I just now need code that does the same scan of the master 0x71 TCA, which we already have I believe, but needs to have one port active at a time with the 0x70 TCA. It also needs to scan the active port and its data then scan its ports as well.

#include "Wire.h"
extern "C" 
{ 
#include "utility/twi.h"  // from Wire library, so we can do bus scanning
}

#define TCAADDR_0 0x71
#define TCAADDR_1 0x70

void tcaselect(uint8_t tcaAddr, uint8_t i) {
  if (i > 7) return;
 
  Wire.beginTransmission(tcaAddr);
  Wire.write(1 << i);
  Wire.endTransmission();  
}


// standard Arduino setup()
void setup()
{
   while (!Serial);
   delay(1000);

   Wire.begin();

   Serial.begin(115200);
   Serial.println("\nTCAScanner ready!");

   for (uint8_t mux = 0x70; mux <= 0x71; mux++)
   {
      Serial.println("Multiplexer #"); Serial.println(mux, HEX);
      for (uint8_t port=0; port<8; port++) 
      {
         tcaselect(mux, port);
         Serial.print("TCA Port #"); Serial.println(port);

         for (uint8_t addr = 0; addr<=127; addr++) 
         {
            if (addr == mux) continue;

            uint8_t data;
            if (! twi_writeTo(addr, &data, 0, 1, 1)) 
            {
               Serial.print("Found I2C 0x");  Serial.println(addr,HEX);
            }
         }
      }
   }
   Serial.println("\ndone");
}

void loop() 
{
}

No idea yet what MPU6250 module you have (read the forum rules).

Method#1 should work if you use an address pin as chip select (connected to a digital pin).
You should post a wiring diagram (read the forum rules).
Leo..

Like I said I've already googled this and found that you actually can connect multiple sensors. Actually with a TCA you can connect up to 64 seperate I2C busses. There is a ton of projects suggesting this. It is just no one gives out code and no one is willing to help. Like I said it doesn't matter about what I've posted because I happened to post this topic and all I am doing is asking. I can't delete them anyway. I'm pretty sure I provided a lot of information. I talked about the product I was using and how I was trying to apply it. You can't expect me to add much more than that because I don't have code for it nor much experience. I also changed my design idea since making those posts so there is no way I am gonna stick with the same post that is six pages under.

Hi,
google arduino using multiple i2c devices

Tom... :slight_smile:

I am talking about the TCA, but I am using the mpu9250. Thanks

Still don't know if you actually NEED the an I2C muxer.
How many MPU6250 boards are you planning to use.

Still no idea which board you're using. It might also have (faster) SPI.

Multiple I2C or SPI devices should be easy.
It's exactly the same as one device (one ever use one I2C address).
You just switch to the next board with the chip select pin, and read the data in a second set of variables.
Leo..

As far as I am concerned that you couldn't connect thirty five of the same i2c busses with the same address because you could only change one mpu to 0x69 and the rest would be 0x68. There aren't enough pin ins on the arduino to accomplish because having them all registered the same would just cause conflicts. Are you saying I can just have a master and slave, but just read one sensor at a time and just have it repeat?

I mean that is what I read on the internet. I guess you could just disable all separate devices when reading one.

For 35 unknown boards you most likely HAVE to use an I2C expander.
Not because of the lack of pins, but because of I2C bus wire length/capacitance.

The TCA9548 itself is an I2C device, and has AFAIK three address pins.
So you can use up to eight TCA boards by selecting different address pin configurations.
Selecting the right board and board channel should be covered in the Adafruit library.
The MPU boards can all be left on the same address.
Leo..

Yep that is exactly why I had chose the TCA. That would make sense to use the A0 A1 and A2 pins to make it so each TCA had a unique address that way I don't have to disable each device while I'm reading from another TCA. This way I could possible read them all at the same time?

If you use multiple TCA in parallel, each one must have a distinct address on your "primary" I2C bus. Each TCA allows to enable or disable independently 8 "secondary" I2C channels. While you can enable all secondary channels at the same time, I'm not sure if this is a good idea, because all pullup resistors in all enabled channels must be driven by the bus master. Consequently you'll enable only one channel at a time, eventually another channel with a different operating voltage (level shifter operation).

So If I have a TCA that is my primary i2c bus and put other TCAs connected to that bus I should just have to disable each port besides one of them and read one at a time? Instead of making it so that I could read all of them at the same time?

You can have five TCA chips connected to the primary Arduino I2C bus.
Each TCA board must be configurated for a different fixed I2C address by connecting the three address lines to power or ground.
First chip, all address pins LOW is address 0x70
Second chip, only A0 connected to VCC is address 0x71
Third chip, only A1 connected to VCC is address 0x72
Fourth chip, A0 and A1 connected to VCC is address 0x73
Fifth chip, only A2 connected to VCC is address 0x74

Don't know why you think you can read them "all at the same time" with a single MCU.
Leo..