LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

TCA9548A Adafruit i2C Multiplexer Labview Example?

Solved!
Go to solution

I have a working i2C Labview program using NI USB-8451.  I want to use a TCA9548A Muliplexer so I can switch SDA and SCL ports.  The best I understand with the TCA9548A is you address at 70 and write 0 - 7 to switch the i2C channels.  After writing 1,  I thought it would open Channel 1 and I could then do normal i2C reading/writing.

 

I can read/write to the TCA9548A, but, I can never go past the TCA9548A to another port to read i2C data.  What I did is simple, I took a known working i2C harness and spliced the TCA9548A into the SDA and SCL lines.

 

The error message is always the same from Labview:

"Error -301742 occurred at NI-845x I2C Write Read.vi:1370002

Possible reason(s):

NI-845x: The slave did not acknowledge an address+direction byte transmitted by the I2C master. If you are using ACK polling, consider increasing the timeout. Other reasons include the incorrect address set in the I2C configuration or the incorrect use of the 7-bit address. When entering an address to access a 7-bit device, do not include the direction bit. The NI-845x Basic I2C API internally sets the direction bit to the correct value, depending on the function (write or read). If your datasheet specifies the 7-bit device address as a byte, discard the direction bit (bit 0) and right-shift the byte value by one to create the 7-bit address."

 

Does anyone have a working example of Labview code and the TCA9548A?  Or can anyone look at my code and tell me what I'm doing wrong?

 

Attached are some screenshots of my code and front panel.

 

Thank you!

Download All
0 Kudos
Message 1 of 12
(7,169 Views)

@Dhubbell wrote:

I have a working i2C Labview program using NI USB-8451.  I want to use a TCA9548A Muliplexer so I can switch SDA and SCL ports.  The best I understand with the TCA9548A is you address at 70 and write 0 - 7 to switch the i2C channels.  After writing 1,  I thought it would open Channel 1 and I could then do normal i2C reading/writing.

 


Writing a value of 1 to the control register doesn't open channel 1, it opens channel 0. To open channel 1 you need to write the value 2. The eight channels are mapped to the eight bits in the control register.

table.png

Message 2 of 12
(7,156 Views)

Thank you arteitle for your reply and suggestion.  I have tried different address values including 2 and I still cannot read data.

 

Can you confirm my belief on the behavior of this TCA9548A Chip?  

I think the TCA9548A is supposed to take a MASTER SDA and SCL from the USB-8451, then switch to a channel PORT.  This way I will only have one active PORT open at a time.  I'm not trying any other i2C on the bus right now, I only have one connected.  My hope is that I can have multiple i2C devices with the same address and switch to one port at a time using the TCA9548A.

 

Can you think of any other ways of checking these values in NI I/O trace?  See my attached NI IO traces...with TCA9548A code and with TCA9548A removed.

 

NI-IO-TRACE WITH NO TCA9548A.jpgNI-IO-TRACE WITH TCA9548A CODE AND FAILED READ.jpg

 

Thank you!

0 Kudos
Message 3 of 12
(7,144 Views)

Unfortunately I don't have any experience with the USB-8451, but I do have experience with I2C. You're correct about what the TCA9548A can be used for; you should be able to connect any or all of the eight channels to the master by sending the chip the appropriate command, allowing you to select between multiple devices with the same address. Can you share a drawing of your circuit so we can make sure the TCA9548A is connected correctly? 

Message 4 of 12
(7,121 Views)

Thank you for showing Interest.  I appreciate your help.

 

Here's a crude drawing I did by hand to help illustrate how I have it hooked up.   I'm thinking I should be able to do this sequence:

1)  Address the TCA9548A at the default address 0x70.

2)  Write a Channel Number to the TCA9548A and the channel or port then becomes open to i2c commands.

So far I can verify I'm reading and writing values to the TCA9548A

3)  At this point, my belief is after the channel or port is open, then I can address other i2C on the port that is open.  When I try to read the Temp Sensor SE97B at Address 0x18, I get nothing.

 

After I open the port/channel on the TCA9548A, do I need to address the SE97B differently than the original address of 0x18?  It's no longer a direct connect, but, it goes through the TCA9548A.

 

Thanks again for looking this over for me!

Wired TCA9548A-V3.jpg

0 Kudos
Message 5 of 12
(7,114 Views)

Does the USB-8451 have built-in pull-ups on its SDA and SCL pins? From what I've been able to find it looks like no. There need to be separate pull-ups on all of the TCA9548A's I2C ports, as well as on its RESET# line. With the SE97B connected directly to the 8451, the 10k resistors you show will pull the I2C bus between the SE97B and 8451 up to 3.3V. But with the TCA9548A in between, if you're powering it from 5V like you show, then you'll also need separate pull-ups to 5V on its SDA, SCL, and RESET# pins. Regarding #2, again, you don't write a channel number to the TCA9548A, you write a 1 to the bit corresponding to the port(s) you want to enable. Once the port is enabled you can talk to the device on it just like you would if it were directly connected, no special addressing needed.

Message 6 of 12
(7,109 Views)

@arteitle

Thank you for the suggestion.  Let me try this next week and I'll report my findings.  You've been extremely helpful.

0 Kudos
Message 7 of 12
(7,099 Views)

Hey could you share your solution , I am trying to use the I2C multiplexer and am not able to read the acknowledgement bit after writing the values to the driver board.

0 Kudos
Message 8 of 12
(6,975 Views)
Solution
Accepted by topic author Dhubbell

@Hazmat wrote:

Hey could you share your solution , I am trying to use the I2C multiplexer and am not able to read the acknowledgement bit after writing the values to the driver board.


Here's a simple vi that will toggle between two addresses on the TCA9548A using NI-USB-8451.  I hope this helps.  After you toggle the TCA9548A, then all normal i2c commands will be acknowledged as if you were directly connected.

 

0 Kudos
Message 9 of 12
(6,963 Views)

Thank you... It worked!!

0 Kudos
Message 10 of 12
(6,931 Views)