slvrdragon50
Posts: 3
Joined: Sat Sep 03, 2016 1:54 am

TCA9548a Multiplex Channel Switch Help

Tue Jun 27, 2017 2:42 pm

Hi

I'm struggling to get wiringPi to work with my TCA9548a on my Pi 3 using C code. I believe I do have a working channel switcher, but I am unable to detect my sensors (BNO055). This is how I am switching channels where "address"=fd, SWITCH = 0x04, switch register for the TCA9548a, and "channel" is what chanel I want to switch to.

Code: Select all

void BNO055::switch_channel(){

	int check;

	check = wiringPiI2CWrite(SWITCH, channel);

	//~ check = wiringPiI2CWriteReg8(address, SWITCH, channel);

	if (check==-1)

		printf("could not switch");

	else

		printf("Switched to channel: %i \n",channel);

}
I can't tell if it is actually switching or not since I can put in an incorrect channel byte, and it still says it has switched.

This is what I have defined for the mux channels: In binary, they are 10000000, 01000000, 00100000, etc.

Code: Select all

//MUX Channels

#define CH0 0x01

#define CH1 0x02

#define CH2 0x04

#define CH3 0x08

#define CH4 0x10

#define CH5 0x20

#define CH6 0x40

#define CH7 0x80
I started looking into the dtoverlay=PCA9548 line as well in the boot config, and this might be a good option too, but I was unsure on implementation. I know it is a simple access different buses to overcome the multiplexer code, but is there a way for me to quickly check that the sensors are detected in the bus? I am running i2cdetect -y (3-10), and each i2cdetect returns a UU on 0x70 (multiplexer address). Is that correct? Shouldn't it be detecting the sensor address (0x28)?

In summary:
1) Are the channel 8-bit switch mask values correct?
2) Can I quickly see if the sensors are being detected using the dtoverlay without rewriting all of my code?

Much thanks

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 9069
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: TCA9548a Multiplex Channel Switch Help

Tue Jun 27, 2017 3:42 pm

slvrdragon50 wrote:I started looking into the dtoverlay=PCA9548 line as well in the boot config, and this might be a good option too, but I was unsure on implementation. I know it is a simple access different buses to overcome the multiplexer code, but is there a way for me to quickly check that the sensors are detected in the bus? I am running i2cdetect -y (3-10), and each i2cdetect returns a UU on 0x70 (multiplexer address). Is that correct? Shouldn't it be detecting the sensor address (0x28)?

In summary:
1) Are the channel 8-bit switch mask values correct?
2) Can I quickly see if the sensors are being detected using the dtoverlay without rewriting all of my code?
Yes, your values look correct. I would say that wiringPiI2CWriteReg8 is using smbus writes when the TCA9548 is not an SMBus device. SMbus will try writing a register address field first which is not required by the mux. The datasheet does state "There is no limit to the number of bytes sent, but the last byte sent is what is in the register", so it shouldn't matter.
I don't know where you got your "SWITCH = 0x04" value from, but based on that the value is irrelevant.

"man i2cdetect"
INTERPRETING THE OUTPUT
Each cell in the output table will contain one of the following symbols:

· "--". The address was probed but no chip answered.

· "UU". Probing was skipped, because this address is currently in use by a driver. This strongly suggests that there is a chip at this address.

· An address number in hexadecimal, e.g. "2d" or "4e". A chip was found at this address.
I would expect to see your address 0x28 show up if the chip is detected, which implies there is a wiring issue.

Have you added any pull up resistors to the outputs of the mux, or does your sensor provide some? Without those you will have problems as devices only ever pull the line down.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

slvrdragon50
Posts: 3
Joined: Sat Sep 03, 2016 1:54 am

Re: TCA9548a Multiplex Channel Switch Help

Tue Jun 27, 2017 5:13 pm

Ahh. I got the 0x04 from my Python code which does work using I2C and smbus. I'm guessing this is a difference between languages, and C doesn't using smbus. The only C code I can find is Arduino code which uses Wire.

I'm using Adafruit's BNO055, and I believe it has the resistors already installed? I know the sensors and wiring work since I can collect data using my Python code.

edit:
Ahhh sorry. I am an idiot! I was thinking bus 3 was channel 2 on my mux... It's actually channel 1 which is disconnected. The dtoverlay works properly. I think I will just rewrite the code to access each bus then. This is seriously a very cool thing you have written!

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 9069
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: TCA9548a Multiplex Channel Switch Help

Tue Jun 27, 2017 8:05 pm

slvrdragon50 wrote:Ahhh sorry. I am an idiot! I was thinking bus 3 was channel 2 on my mux... It's actually channel 1 which is disconnected. The dtoverlay works properly. I think I will just rewrite the code to access each bus then. This is seriously a very cool thing you have written!
I can't claim the credit - I only put together the overlay. Glad you've solved your problem.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Interfacing (DSI, CSI, I2C, etc.)”