Skip to content

Commit fc83b82

Browse files
committed
0.2.1 TCA9548
1 parent 6d0c771 commit fc83b82

File tree

13 files changed

+487
-85
lines changed

13 files changed

+487
-85
lines changed

libraries/TCA9548/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.2.1] - 2023-12-09
10+
- add derived classes
11+
- PCA9543 (2 channel), PCA9545 (4 channel), PCA9546 (4 channel)
12+
- add **uint8_t getInterruptMask()**
13+
- fix begin() : remove wire-> begin() as dependency should be outside lib
14+
- fix readme.md
15+
16+
917
## [0.2.0] - 2023-12-09
1018
- refactor API, begin()
1119
- update readme.md

libraries/TCA9548/README.md

Lines changed: 69 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,42 @@
1111

1212
# TCA9548
1313

14-
Arduino Library for TCA9548 I2C multiplexer.
14+
Arduino Library for TCA9548 I2C multiplexer and compatibles.
1515

1616

1717
## Description
1818

19-
Library for the TCA9548 and TCA9548a (PCA9548, PCA9548a) I2C multiplexer.
19+
Library for the TCA9548 and TCA9548a 8 channel I2C multiplexer.
2020

21-
The library allows you to enable 0 to 7 I2C channels (ports) uniquely or simultaneously.
22-
This is especially useful if you have multiple devices/sensors that have a fixed address,
23-
or you have address conflicts between I2C devices
21+
Compatible with PCA9548, PCA9548a, PCA9546, PCA9545, PCA9543.
22+
23+
The library allows you to enable 0 to 7 I2C channels (SDA + SCL) uniquely or simultaneously.
24+
In fact the TCA9548 is therefore a **switch**, although often named a multiplexer.
25+
A multiplexer is useful if you have
26+
- multiple identical devices that have a fixed address,
27+
- a too small address range or
28+
- if there are address conflicts between different I2C devices.
29+
30+
The library caches the channels enabled, and if a channel is enabled,
31+
it will not be enabled again (low level) to optimize performance.
32+
33+
The device works with 2.3 V to 5.5 V so it should work with most MCU's.
2434

2535
**Warning**
2636
The library is not tested extensively.
2737

38+
39+
#### I2C
40+
2841
I2C address of the device itself is 0x70 .. 0x77.
29-
This address may not be used on any of the I2C channels of course.
42+
This address can not be used on any of the I2C channels of course.
3043

31-
The library caches the channels enabled, and if a channel is enabled,
32-
it will not be enabled again (low level) to optimize performance.
44+
Note if your first multiplexer is 0x70, you may have an array of 0x71 multiplexers behind it.
45+
(This will give 8 x 8 = 64 I2C buses, a lot of admin overhead and probably performance penalties).
46+
47+
Pull-up resistors are required on all upstream and downstream channels.
48+
49+
The TCA9548 can work up to 400 KHz according to the datasheet.
3350

3451

3552
#### 0.2.0 Breaking change
@@ -38,28 +55,30 @@ Version 0.2.0 introduced a breaking change.
3855
You cannot set the pins in **begin()** any more.
3956
This reduces the dependency of processor dependent Wire implementations.
4057
The user has to call **Wire.begin()** and can optionally set the Wire pins
41-
before calling **begin()**.
58+
before calling the TCA9548 **begin()**.
4259

4360

4461
#### Compatible devices
4562

46-
This library is expected to work for the PCA9548(a) too as the TCA is pin compatible newer version.
63+
This library is expected to work for the following devices: (since 0.2.1)
4764

48-
| Device | Tested | Notes |
49-
|:-----------|:--------:|:-------:|
50-
| TCA9548s | n |
51-
| PCA9548 | n | see links below |
52-
| PCA9548a | n |
65+
| device | address | channel | interrupt | reset | verified | notes |
66+
|:---------:|:---------:|:---------:|:-----------:|:-------:|:----------:|:-------:|
67+
| PCA9543 | 4 | 2 | Y | Y | N |
68+
| PCA9545 | 4 | 4 | Y | Y | N |
69+
| PCA9546 | 8 | 4 | | Y | N |
70+
| PCA9548 | 8 | 8 | | Y | N | equals TCA9648
71+
| PCA9548 | 8 | 8 | | Y | N | equals TCA9648
5372

5473

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

5676
There are however small differences, check the data sheets to see the details.
5777
- [difference TCA PCA](https://e2e.ti.com/support/interface-group/interface/f/interface-forum/815758/faq-what-is-the-difference-between-an-i2c-device-with-the-family-name-pca-and-tca)
5878
- https://electronics.stackexchange.com/questions/209616/is-nxps-pca9548a-compatible-with-tis-tca9548a
5979
- https://www.nxp.com/docs/en/application-note/AN262.pdf
6080

6181

62-
6382
#### Related
6483

6584
- https://github.com/RobTillaart/HC4051 (1x8 mux)
@@ -78,52 +97,62 @@ There are however small differences, check the data sheets to see the details.
7897

7998
- **TCA9548(const uint8_t deviceAddress, TwoWire \*wire = &Wire)** Constructor.
8099
deviceAddress = 0x70 .. 0x77, wire = Wire or WireN.
81-
- **bool begin(uint8_t dataPin, uint8_t clockPin, uint8_t mask = 0x00)** Set I2C pins for ESP32.
82-
Set mask of channels to be enabled, default all disabled.
83100
- **bool begin(uint8_t mask = 0x00)** set mask of channels to be enabled, default all disabled.
84101
- **bool isConnected()** returns true if address of the multiplexer is found on I2C bus.
85102

86103

87-
The derived class PCA9548 has same interface, except constructor.
104+
The derived classes PCA9548/PCA9546 have the same interface, except constructor.
105+
(see #15)
88106

89107
- **PCA9548(const uint8_t deviceAddress, TwoWire \*wire = &Wire)** Constructor.
90-
deviceAddress = 0x70 .. 0x77, wire = Wire or WireN.
108+
- **PCA9546(const uint8_t deviceAddress, TwoWire \*wire = &Wire)** Constructor.
109+
- **PCA9545(const uint8_t deviceAddress, TwoWire \*wire = &Wire)** Constructor.
110+
- **PCA9543(const uint8_t deviceAddress, TwoWire \*wire = &Wire)** Constructor.
91111

92112

93113
#### Find device
94114

95115
- **bool isConnected(uint8_t address)** returns true if arbitrary address is found on I2C bus.
96-
This can be used to verify a certain device is available (or not) on an enabled channel.
116+
This can be used to verify if a certain device is available (or not) on an **enabled** channel.
117+
So it does not scan all 8 channels to see if any of them has a device with the address given.
97118

98119

99120
#### Channel functions
100121

101122
All "channel functions" return true on success.
102123

103-
- **bool enableChannel(uint8_t channel)** enables channel 0 .. 7 non-exclusive.
124+
- **bool enableChannel(uint8_t channel)** enables channel 0 .. 7 **non-exclusive**.
104125
Multiple channels can be enabled in parallel.
105126
- **bool disableChannel(uint8_t channel)** disables channel 0 .. 7.
106127
Will not disable other channels.
107-
- **bool selectChannel(uint8_t channel)** enables a single channel 0 .. 7 exclusive.
128+
- **bool selectChannel(uint8_t channel)** enables a single channel 0 .. 7 **exclusive**.
108129
All other channels will be disabled in the same call, so not before or after.
109130
- **bool isEnabled(uint8_t channel)** returns true if the channel is enabled.
110-
- **bool disableAllChannels()** fast way to disable all.
131+
- **bool disableAllChannels()** fast way to disable all channels.
132+
133+
Multiple channels can also be enabled in one call with a mask.
134+
111135
- **bool setChannelMask(uint8_t mask)** enables 0 or more channels simultaneously with a bit mask.
112136
- **uint8_t getChannelMask()** reads back the bit mask of the channels enabled.
113137

114138

115139
#### Reset
116140

117-
- **void setResetPin(uint8_t resetPin)** sets the pin to reset the chip. (Not tested)
141+
Optional the library can reset the device.
142+
143+
- **void setResetPin(uint8_t resetPin)** sets the pin to reset the chip.
118144
- **void reset()** trigger the reset pin.
145+
146+
#### Debug
147+
119148
- **int getError()** returns the last I2C error.
120149

121150

122151
#### Forced IO
123152

124-
When forced IO is set all writes and read - **getChannelMask()** - will go to the device.
125-
If the flag is set to false it will cache the value of the channels enabled.
126-
This will result in more responsive / faster calls.
153+
When forced IO is set, all writes and read, e.g. **uint8_t getChannelMask()**, will go to the device.
154+
If the **forced-IO** flag is set to false, it will cache the value of the channels enabled.
155+
This will result in far more responsive and faster calls.
127156
Note that writes are only optimized if the channels are already set.
128157

129158
- **void setForced(bool forced = false)** set forced write, slower but more robust.
@@ -132,39 +161,27 @@ Note that writes are only optimized if the channels are already set.
132161
- **bool getForced()** returns set flag.
133162

134163

164+
#### Interrupts
165+
166+
The PCA9545 and PCA9543 support interrupts.
167+
These two derived classes have implemented the
168+
169+
- **uint8_t getInterruptMask()** function that returns a bit mask of interrupts set.
170+
171+
135172
## Error Codes
136173

137-
Not implemented yet, preparation for 0.2.0.
174+
Not implemented yet, preparation for future.
138175

139176
| name | value | description |
140177
|:------------------------|:-------:|:------------------------|
141-
| TCA9548_OK | 00 | no error |
178+
| TCA9548_OK | 00 | no error |
142179
| TCA9548_ERROR_I2C | -10 | detected an I2C error |
143180
| TCA9548_ERROR_CHANNEL | -20 | channel out of range |
144181

145182

146183
## Future
147184

148-
#### PCA954X family
149-
150-
To investigate if these can be made in one derived class tree.
151-
152-
| chip | address | channel | interrupt | reset | notes |
153-
|:---------:|:---------:|:---------:|:-----------:|:-------:|:-------:|
154-
| PCA9540 | - | 2 | | | address programmable
155-
| PCA9641 | 4 pins | 2 | | | master selector
156-
| PCA9542 | 3 pins | 2 | Y | |
157-
| PCA9543 | 2 pins | 2 | Y | Y |
158-
| PCA9544 | 3 pins | 4 | Y | |
159-
| PCA9545 | 2 pins | 4 | Y | Y |
160-
| PCA9546 | 3 pins | 4 | | Y |
161-
| PCA9548 | 3 pins | 8 | | Y | equals TCA9648
162-
163-
- Most could work if a "channels" was defined and if internals are enough similar.
164-
- RESET pin is supported in TCA9548
165-
- INT is more a user code issue.
166-
- might need a **type()**?
167-
168185

169186
#### Must
170187

@@ -174,17 +191,13 @@ To investigate if these can be made in one derived class tree.
174191
#### Should
175192

176193
- add examples.
177-
- test test and test.
178-
- write unit test.
179-
- create derived classes for compatible devices (0.2.0).
180-
- see above PCA9548 and PCA9548a.
181-
- investigate support derived classes
182-
194+
- test with hardware.
183195

184196
#### Could
185197

186198
- set an "always enabled" mask.
187199
- investigate the consequences!
200+
- extend the unit tests.
188201

189202
#### Wont
190203

0 commit comments

Comments
 (0)