RobTillaart / TCA9548

Arduino library for TCA9548 8 channel I2C multiplexer and compatibles.
MIT License
20 stars 7 forks source link
arduino i2c multiplexer

Arduino CI Arduino-lint JSON check GitHub issues

License: MIT GitHub release PlatformIO Registry

TCA9548

Arduino Library for TCA9548 I2C multiplexer and compatibles.

Description

Library for the TCA9548 and TCA9548a 8 channel I2C multiplexer.

Compatible with PCA9548, PCA9548a, PCA9546, PCA9545, PCA9543.

The library allows you to enable 0 to 7 I2C channels (SDA + SCL) uniquely or simultaneously. In fact the TCA9548 is therefore a switch, although often named a multiplexer. A multiplexer is useful if you have

The library caches the channels enabled, and if a channel is enabled, it will not be enabled again (low level) to optimize performance.

The device works with 2.3 V to 5.5 V so it should work with most MCU's.

Warning The library is not tested extensively.

I2C

I2C address of the device itself is 0x70 .. 0x77. This address can not be used on any of the I2C channels of course.

Note if your first multiplexer is 0x70, you may have an array of 0x71 multiplexers behind it. (This will give 8 x 8 = 64 I2C buses, a lot of admin overhead and probably performance penalties).

Pull-up resistors are required on all upstream and downstream channels.

The TCA9548 can work up to 400 KHz according to the datasheet.

0.2.0 Breaking change

Version 0.2.0 introduced a breaking change. You cannot set the pins in begin() any more. This reduces the dependency of processor dependent Wire implementations. The user has to call Wire.begin() and can optionally set the Wire pins before calling the TCA9548 begin().

Compatible devices

This library is expected to work for the following devices: (since 0.2.1)

device address channel interrupt reset verified notes
PCA9543 4 2 Y Y N
PCA9545 4 4 Y Y N
PCA9546 8 4 Y N
PCA9548 8 8 Y N equals TCA9648
PCA9548 8 8 Y N equals TCA9648

Note: these are not tested with hardware yet, please share your experiences.

There are however small differences, check the data sheets to see the details.

Related

Interface

#include "TCA9548.h"

Constructor

The derived classes PCA9548/PCA9546 have the same interface, except constructor. (see #15)

Find device

Channel functions

All "channel functions" return true on success.

Multiple channels can also be enabled in one call with a mask.

Reset

Optional the library can reset the device.

Debug

Forced IO

When forced IO is set, all writes and read, e.g. uint8_t getChannelMask(), will go to the device. If the forced-IO flag is set to false, it will cache the value of the channels enabled. This will result in far more responsive and faster calls. Note that writes are only optimized if the channels are already set.
Forced IO is also used to speed up getChannelMask().

Interrupts

(not tested)

The PCA9545 and PCA9543 support interrupts. These two derived classes have implemented the

Error Codes

Not implemented yet, preparation for future.

name value description
TCA9548_OK 00 no error
TCA9548_ERROR_I2C -10 detected an I2C error
TCA9548_ERROR_CHANNEL -20 channel out of range

Future

Must

Should

Could

Wont

Support

If you appreciate my libraries, you can support the development and maintenance. Improve the quality of the libraries by providing issues and Pull Requests, or donate through PayPal or GitHub sponsors.

Thank you,