11
11
12
12
# TCA9548
13
13
14
- Arduino Library for TCA9548 I2C multiplexer.
14
+ Arduino Library for TCA9548 I2C multiplexer and compatibles .
15
15
16
16
17
17
## Description
18
18
19
- Library for the TCA9548 and TCA9548a (PCA9548, PCA9548a) I2C multiplexer.
19
+ Library for the TCA9548 and TCA9548a 8 channel I2C multiplexer.
20
20
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.
24
34
25
35
** Warning**
26
36
The library is not tested extensively.
27
37
38
+
39
+ #### I2C
40
+
28
41
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.
30
43
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.
33
50
34
51
35
52
#### 0.2.0 Breaking change
@@ -38,28 +55,30 @@ Version 0.2.0 introduced a breaking change.
38
55
You cannot set the pins in ** begin()** any more.
39
56
This reduces the dependency of processor dependent Wire implementations.
40
57
The user has to call ** Wire.begin()** and can optionally set the Wire pins
41
- before calling ** begin()** .
58
+ before calling the TCA9548 ** begin()** .
42
59
43
60
44
61
#### Compatible devices
45
62
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)
47
64
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
53
72
54
73
74
+ Note: these are not tested with hardware yet, please share your experiences.
55
75
56
76
There are however small differences, check the data sheets to see the details.
57
77
- [ 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 )
58
78
- https://electronics.stackexchange.com/questions/209616/is-nxps-pca9548a-compatible-with-tis-tca9548a
59
79
- https://www.nxp.com/docs/en/application-note/AN262.pdf
60
80
61
81
62
-
63
82
#### Related
64
83
65
84
- https://github.com/RobTillaart/HC4051 (1x8 mux)
@@ -78,52 +97,62 @@ There are however small differences, check the data sheets to see the details.
78
97
79
98
- ** TCA9548(const uint8_t deviceAddress, TwoWire \* wire = &Wire)** Constructor.
80
99
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.
83
100
- ** bool begin(uint8_t mask = 0x00)** set mask of channels to be enabled, default all disabled.
84
101
- ** bool isConnected()** returns true if address of the multiplexer is found on I2C bus.
85
102
86
103
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 )
88
106
89
107
- ** 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.
91
111
92
112
93
113
#### Find device
94
114
95
115
- ** 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.
97
118
98
119
99
120
#### Channel functions
100
121
101
122
All "channel functions" return true on success.
102
123
103
- - ** bool enableChannel(uint8_t channel)** enables channel 0 .. 7 non-exclusive.
124
+ - ** bool enableChannel(uint8_t channel)** enables channel 0 .. 7 ** non-exclusive** .
104
125
Multiple channels can be enabled in parallel.
105
126
- ** bool disableChannel(uint8_t channel)** disables channel 0 .. 7.
106
127
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** .
108
129
All other channels will be disabled in the same call, so not before or after.
109
130
- ** 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
+
111
135
- ** bool setChannelMask(uint8_t mask)** enables 0 or more channels simultaneously with a bit mask.
112
136
- ** uint8_t getChannelMask()** reads back the bit mask of the channels enabled.
113
137
114
138
115
139
#### Reset
116
140
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.
118
144
- ** void reset()** trigger the reset pin.
145
+
146
+ #### Debug
147
+
119
148
- ** int getError()** returns the last I2C error.
120
149
121
150
122
151
#### Forced IO
123
152
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.
127
156
Note that writes are only optimized if the channels are already set.
128
157
129
158
- ** 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.
132
161
- ** bool getForced()** returns set flag.
133
162
134
163
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
+
135
172
## Error Codes
136
173
137
- Not implemented yet, preparation for 0.2.0 .
174
+ Not implemented yet, preparation for future .
138
175
139
176
| name | value | description |
140
177
| :------------------------| :-------:| :------------------------|
141
- | TCA9548_OK | 00 | no error |
178
+ | TCA9548_OK | 00 | no error |
142
179
| TCA9548_ERROR_I2C | -10 | detected an I2C error |
143
180
| TCA9548_ERROR_CHANNEL | -20 | channel out of range |
144
181
145
182
146
183
## Future
147
184
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
-
168
185
169
186
#### Must
170
187
@@ -174,17 +191,13 @@ To investigate if these can be made in one derived class tree.
174
191
#### Should
175
192
176
193
- 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.
183
195
184
196
#### Could
185
197
186
198
- set an "always enabled" mask.
187
199
- investigate the consequences!
200
+ - extend the unit tests.
188
201
189
202
#### Wont
190
203
0 commit comments