{"id":20989980,"url":"https://github.com/robtillaart/tca9548","last_synced_at":"2025-05-14T18:32:24.090Z","repository":{"id":45242194,"uuid":"348318954","full_name":"RobTillaart/TCA9548","owner":"RobTillaart","description":"Arduino library for TCA9548 8 channel I2C multiplexer and compatibles.","archived":false,"fork":false,"pushed_at":"2024-04-18T15:52:45.000Z","size":52,"stargazers_count":21,"open_issues_count":0,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-02T05:56:48.168Z","etag":null,"topics":["arduino","i2c","multiplexer"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RobTillaart.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"RobTillaart","custom":"https://www.paypal.me/robtillaart"}},"created_at":"2021-03-16T11:19:08.000Z","updated_at":"2024-07-26T04:00:05.673Z","dependencies_parsed_at":"2024-07-26T04:00:00.751Z","dependency_job_id":"690962e8-e9c2-4e84-9b7a-9546bbd68d18","html_url":"https://github.com/RobTillaart/TCA9548","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FTCA9548","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FTCA9548/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FTCA9548/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobTillaart%2FTCA9548/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobTillaart","download_url":"https://codeload.github.com/RobTillaart/TCA9548/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225305836,"owners_count":17453466,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","i2c","multiplexer"],"created_at":"2024-11-19T06:27:06.100Z","updated_at":"2024-11-19T06:27:06.532Z","avatar_url":"https://github.com/RobTillaart.png","language":"C++","funding_links":["https://github.com/sponsors/RobTillaart","https://www.paypal.me/robtillaart"],"categories":[],"sub_categories":[],"readme":"\n[![Arduino CI](https://github.com/RobTillaart/TCA9548/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)\n[![Arduino-lint](https://github.com/RobTillaart/TCA9548/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/TCA9548/actions/workflows/arduino-lint.yml)\n[![JSON check](https://github.com/RobTillaart/TCA9548/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/TCA9548/actions/workflows/jsoncheck.yml)\n[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/TCA9548.svg)](https://github.com/RobTillaart/TCA9548/issues)\n\n[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/TCA9548/blob/master/LICENSE)\n[![GitHub release](https://img.shields.io/github/release/RobTillaart/TCA9548.svg?maxAge=3600)](https://github.com/RobTillaart/TCA9548/releases)\n[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/TCA9548.svg)](https://registry.platformio.org/libraries/robtillaart/TCA9548)\n\n\n# TCA9548\n\nArduino Library for TCA9548 I2C multiplexer and compatibles.\n\n\n## Description\n\nLibrary for the TCA9548 and TCA9548a 8 channel I2C multiplexer.\n\nCompatible with PCA9548, PCA9548a, PCA9546, PCA9545, PCA9543.\n\nThe library allows you to enable 0 to 7 I2C channels (SDA + SCL) uniquely or simultaneously.\nIn fact the TCA9548 is therefore a **switch**, although often named a multiplexer.\nA multiplexer is useful if you have \n- multiple identical devices that have a fixed address,\n- a too small address range or \n- if there are address conflicts between different I2C devices.\n\nThe library caches the channels enabled, and if a channel is enabled,\nit will not be enabled again (low level) to optimize performance.\n\nThe device works with 2.3 V to 5.5 V so it should work with most MCU's.\n\n**Warning**\nThe library is not tested extensively.\n\n\n#### I2C \n\nI2C address of the device itself is 0x70 .. 0x77.\nThis address can not be used on any of the I2C channels of course.\n\nNote if your first multiplexer is 0x70, you may have an array of 0x71 multiplexers behind it.\n(This will give 8 x 8 = 64 I2C buses, a lot of admin overhead and probably performance penalties).\n\nPull-up resistors are required on all upstream and downstream channels.\n\nThe TCA9548 can work up to 400 KHz according to the datasheet.\n\n\n#### 0.2.0 Breaking change\n\nVersion 0.2.0 introduced a breaking change.\nYou cannot set the pins in **begin()** any more.\nThis reduces the dependency of processor dependent Wire implementations.\nThe user has to call **Wire.begin()** and can optionally set the Wire pins \nbefore calling the TCA9548 **begin()**.\n\n\n#### Compatible devices\n\nThis library is expected to work for the following devices: (since 0.2.1)\n\n|  device   |  address  |  channel  |  interrupt  |  reset  |  verified  |  notes  |\n|:---------:|:---------:|:---------:|:-----------:|:-------:|:----------:|:-------:|\n|  PCA9543  |     4     |     2     |      Y      |    Y    |      N     |\n|  PCA9545  |     4     |     4     |      Y      |    Y    |      N     |\n|  PCA9546  |     8     |     4     |             |    Y    |      N     |\n|  PCA9548  |     8     |     8     |             |    Y    |      N     |  equals TCA9648 \n|  PCA9548  |     8     |     8     |             |    Y    |      N     |  equals TCA9648 \n\n\nNote: these are not tested with hardware yet, please share your experiences.\n\nThere are however small differences, check the data sheets to see the details.\n- [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)\n- https://electronics.stackexchange.com/questions/209616/is-nxps-pca9548a-compatible-with-tis-tca9548a\n- https://www.nxp.com/docs/en/application-note/AN262.pdf\n\n\n#### Related\n\n- https://github.com/RobTillaart/HC4051  (1x8 mux)\n- https://github.com/RobTillaart/HC4052  (2x4 mux)\n- https://github.com/RobTillaart/HC4053  (3x2 mux)\n- https://github.com/RobTillaart/HC4067  (1x16 mux)\n\n\n## Interface\n\n```cpp\n#include \"TCA9548.h\"\n```\n\n#### Constructor\n\n- **TCA9548(const uint8_t deviceAddress, TwoWire \\*wire = \u0026Wire)** Constructor.\ndeviceAddress = 0x70 .. 0x77, wire = Wire or WireN.\n- **bool begin(uint8_t mask = 0x00)**  set mask of channels to be enabled, default all disabled.\n- **bool isConnected()** returns true if address of the multiplexer is found on I2C bus.\n\nThe derived classes PCA9548/PCA9546 have the same interface, except constructor.\n(see #15)\n\n- **PCA9548(const uint8_t deviceAddress, TwoWire \\*wire = \u0026Wire)** Constructor.\n- **PCA9546(const uint8_t deviceAddress, TwoWire \\*wire = \u0026Wire)** Constructor.\n- **PCA9545(const uint8_t deviceAddress, TwoWire \\*wire = \u0026Wire)** Constructor.\n- **PCA9543(const uint8_t deviceAddress, TwoWire \\*wire = \u0026Wire)** Constructor.\n\n\n#### Find device\n\n- **bool isConnected(uint8_t address)** returns true if arbitrary address is found on the \ncurrent I2C bus + selected channels.\nThis can be used to verify if a certain device is available (or not) on any **enabled** channel.\nSo it does not scan all (8) channels to see if any of them has a device with the address given.\n- **bool isConnected(uint8_t address, uint8_t channel)** find address on selected channel.\nNote that this function changes the selected and or enabled channels.\nReturns true if found.\n- **uint8_t find(uint8_t address)** returns a mask with bits set for channels \nwhere the address is found. It scans all channels available.\nNote that this function changes the selected and or enabled channels.\nReturns 0 when the address is not found on any channel, or one bit set per channel found.\n\n\n#### Channel functions\n\nAll \"channel functions\" return true on success.\n\n- **bool enableChannel(uint8_t channel)** enables channel 0 .. 7 **non-exclusive**.  \nMultiple channels can be enabled in parallel.\n- **bool disableChannel(uint8_t channel)** disables channel 0 .. 7.\nWill not disable other channels.\n- **bool selectChannel(uint8_t channel)** enables a single channel 0 .. 7 **exclusive**.  \nAll other channels will be disabled in the same call, so not before or after.\n- **bool isEnabled(uint8_t channel)** returns true if the channel is enabled.\n- **bool disableAllChannels()** fast way to disable all channels.\n\nMultiple channels can also be enabled in one call with a mask.\n\n- **bool setChannelMask(uint8_t mask)** enables 0 or more channels simultaneously with a bit mask.\n- **uint8_t getChannelMask()** reads back the bit mask of the channels enabled.\n\n\n#### Reset\n\nOptional the library can reset the device.\n\n- **void setResetPin(uint8_t resetPin)** sets the pin to reset the chip.\n- **void reset()** trigger the reset pin.\n\n\n#### Debug\n\n- **int getError()** returns the last (I2C) status / error.\n\n\n#### Forced IO\n\nWhen forced IO is set, all writes and read, e.g. **uint8_t getChannelMask()**, will go to the device.\nIf the **forced-IO** flag is set to false, it will cache the value of the channels enabled.\nThis will result in far more responsive and faster calls.\nNote that writes are only optimized if the channels are already set.  \nForced IO is also used to speed up **getChannelMask()**.\n\n- **void setForced(bool forced = false)** set forced write, slower but more robust.\n  - forced == false == fast mode (default).\n  - forced == true == slower, robust mode.\n- **bool getForced()** returns set flag.\n\n\n#### Interrupts\n\n(not tested)\n\nThe PCA9545 and PCA9543 support interrupts. \nThese two derived classes have implemented the\n\n- **uint8_t getInterruptMask()** function that returns a bit mask of interrupts set.\n\n\n## Error Codes\n\nNot implemented yet, preparation for future.\n\n|  name                   |  value  |  description            |\n|:------------------------|:-------:|:------------------------|\n|  TCA9548_OK             |   00    |  no error               |\n|  TCA9548_ERROR_I2C      |  -10    |  detected an I2C error  |\n|  TCA9548_ERROR_CHANNEL  |  -20    |  channel out of range   |\n\n\n## Future\n\n\n#### Must\n\n- improve documentation.\n- improve error handling.\n\n#### Should\n\n- add examples.\n- test with hardware.\n\n#### Could\n\n- set an \"always enabled\" mask.\n  - investigate the consequences!\n- extend the unit tests.\n- **uint8_t find(address)** returns a mask of channel where address is found\n- restore channel in **isConnected(address, channel);\n- add guard in **reset()**, is the pin set?\n\n\n#### Wont\n\n\n## Support\n\nIf you appreciate my libraries, you can support the development and maintenance.\nImprove the quality of the libraries by providing issues and Pull Requests, or\ndonate through PayPal or GitHub sponsors.\n\nThank you,\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobtillaart%2Ftca9548","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobtillaart%2Ftca9548","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobtillaart%2Ftca9548/lists"}