mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.2.0 TCA9548
This commit is contained in:
parent
ae3eb4f466
commit
68fad4c223
@ -6,11 +6,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.2.0] - 2023-12-09
|
||||
- refactor API, begin()
|
||||
- update readme.md
|
||||
- add derived class PCA9548
|
||||
|
||||
----
|
||||
|
||||
## [0.1.6] - 2023-11-22
|
||||
- update readme.md
|
||||
- update keywords.txt
|
||||
|
||||
|
||||
## [0.1.5] - 2023-02-12
|
||||
- fix #8 ambiguity
|
||||
- update keywords.txt
|
||||
|
@ -32,6 +32,15 @@ The library caches the channels enabled, and if a channel is enabled,
|
||||
it will not be enabled again (low level) to optimize performance.
|
||||
|
||||
|
||||
#### 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 **begin()**.
|
||||
|
||||
|
||||
#### Compatible devices
|
||||
|
||||
This library is expected to work for the PCA9548(a) too as the TCA is pin compatible newer version.
|
||||
@ -43,12 +52,22 @@ This library is expected to work for the PCA9548(a) too as the TCA is pin compat
|
||||
| PCA9548a | n |
|
||||
|
||||
|
||||
|
||||
There are however small differences, check the data sheets to see the details.
|
||||
- [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)
|
||||
- https://electronics.stackexchange.com/questions/209616/is-nxps-pca9548a-compatible-with-tis-tca9548a
|
||||
- https://www.nxp.com/docs/en/application-note/AN262.pdf
|
||||
|
||||
|
||||
|
||||
#### Related
|
||||
|
||||
- https://github.com/RobTillaart/HC4051 (1x8 mux)
|
||||
- https://github.com/RobTillaart/HC4052 (2x4 mux)
|
||||
- https://github.com/RobTillaart/HC4053 (3x2 mux)
|
||||
- https://github.com/RobTillaart/HC4067 (1x16 mux)
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
```cpp
|
||||
@ -65,6 +84,12 @@ Set mask of channels to be enabled, default all disabled.
|
||||
- **bool isConnected()** returns true if address of the multiplexer is found on I2C bus.
|
||||
|
||||
|
||||
The derived class PCA9548 has same interface, except constructor.
|
||||
|
||||
- **PCA9548(const uint8_t deviceAddress, TwoWire \*wire = &Wire)** Constructor.
|
||||
deviceAddress = 0x70 .. 0x77, wire = Wire or WireN.
|
||||
|
||||
|
||||
#### Find device
|
||||
|
||||
- **bool isConnected(uint8_t address)** returns true if arbitrary address is found on I2C bus.
|
||||
@ -120,6 +145,27 @@ Not implemented yet, preparation for 0.2.0.
|
||||
|
||||
## Future
|
||||
|
||||
#### PCA954X family
|
||||
|
||||
To investigate if these can be made in one derived class tree.
|
||||
|
||||
| chip | address | channel | interrupt | reset | notes |
|
||||
|:---------:|:---------:|:---------:|:-----------:|:-------:|:-------:|
|
||||
| PCA9540 | - | 2 | | | address programmable
|
||||
| PCA9641 | 4 pins | 2 | | | master selector
|
||||
| PCA9542 | 3 pins | 2 | Y | |
|
||||
| PCA9543 | 2 pins | 2 | Y | Y |
|
||||
| PCA9544 | 3 pins | 4 | Y | |
|
||||
| PCA9545 | 2 pins | 4 | Y | Y |
|
||||
| PCA9546 | 3 pins | 4 | | Y |
|
||||
| PCA9548 | 3 pins | 8 | | Y | equals TCA9648
|
||||
|
||||
- Most could work if a "channels" was defined and if internals are enough similar.
|
||||
- RESET pin is supported in TCA9548
|
||||
- INT is more a user code issue.
|
||||
- might need a **type()**?
|
||||
|
||||
|
||||
#### Must
|
||||
|
||||
- improve documentation.
|
||||
@ -132,6 +178,7 @@ Not implemented yet, preparation for 0.2.0.
|
||||
- write unit test.
|
||||
- create derived classes for compatible devices (0.2.0).
|
||||
- see above PCA9548 and PCA9548a.
|
||||
- investigate support derived classes
|
||||
|
||||
|
||||
#### Could
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: TCA9548.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.6
|
||||
// VERSION: 0.2.0
|
||||
// DATE: 2021-03-16
|
||||
// PURPOSE: Library for TCA9548 I2C multiplexer
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
#include "TCA9548.h"
|
||||
|
||||
|
||||
TCA9548::TCA9548(const uint8_t deviceAddress, TwoWire *wire)
|
||||
TCA9548::TCA9548(uint8_t deviceAddress, TwoWire *wire)
|
||||
{
|
||||
_address = deviceAddress;
|
||||
_wire = wire;
|
||||
@ -17,25 +17,10 @@ TCA9548::TCA9548(const uint8_t deviceAddress, TwoWire *wire)
|
||||
_resetPin = -1;
|
||||
_forced = false;
|
||||
_error = TCA9548_OK;
|
||||
// _channels = 8;
|
||||
}
|
||||
|
||||
|
||||
#if defined (ESP8266) || defined(ESP32)
|
||||
bool TCA9548::begin(uint8_t dataPin, uint8_t clockPin, uint8_t mask)
|
||||
{
|
||||
if ((dataPin < 255) && (clockPin < 255))
|
||||
{
|
||||
_wire->begin(dataPin, clockPin);
|
||||
} else {
|
||||
_wire->begin();
|
||||
}
|
||||
if (! isConnected()) return false;
|
||||
setChannelMask(mask);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
bool TCA9548::begin(uint8_t mask)
|
||||
{
|
||||
_wire->begin();
|
||||
@ -161,5 +146,14 @@ int TCA9548::getError()
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DERIVED CLASS
|
||||
//
|
||||
PCA9548::PCA9548(uint8_t deviceAddress, TwoWire *wire) : TCA9548(deviceAddress, wire)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: TCA9548.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.6
|
||||
// VERSION: 0.2.0
|
||||
// DATE: 2021-03-16
|
||||
// PURPOSE: Library for TCA9548 I2C multiplexer
|
||||
// URL: https://github.com/RobTillaart/TCA9548
|
||||
@ -12,7 +12,7 @@
|
||||
#include "Wire.h"
|
||||
|
||||
|
||||
#define TCA9548_LIB_VERSION (F("0.1.6"))
|
||||
#define TCA9548_LIB_VERSION (F("0.2.0"))
|
||||
|
||||
|
||||
// ERROR CODES (to be elaborated)
|
||||
@ -26,11 +26,8 @@ class TCA9548
|
||||
{
|
||||
public:
|
||||
// deviceAddress = 0x70 .. 0x77
|
||||
TCA9548(const uint8_t deviceAddress, TwoWire *wire = &Wire);
|
||||
TCA9548(uint8_t deviceAddress, TwoWire *wire = &Wire);
|
||||
|
||||
#if defined (ESP8266) || defined(ESP32)
|
||||
bool begin(uint8_t dataPin, uint8_t clockPin, uint8_t mask = 0x00); // default no channels enabled
|
||||
#endif
|
||||
bool begin(uint8_t mask = 0x00); // default no channels enabled
|
||||
bool isConnected(); // find multiplexer on I2C bus
|
||||
bool isConnected(uint8_t address); // find any address on I2C bus
|
||||
@ -58,13 +55,25 @@ public:
|
||||
int getError();
|
||||
|
||||
|
||||
private:
|
||||
protected:
|
||||
uint8_t _address;
|
||||
TwoWire* _wire;
|
||||
uint8_t _mask; // caching mask = status of channels
|
||||
uint8_t _resetPin; // default not set == -1 (255)
|
||||
bool _forced;
|
||||
int _error;
|
||||
// uint8_t _channels; // future PCA954x support.
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DERIVED CLASS
|
||||
//
|
||||
class PCA9548 : public TCA9548
|
||||
{
|
||||
public:
|
||||
PCA9548(uint8_t deviceAddress, TwoWire *wire = &Wire);
|
||||
};
|
||||
|
||||
|
||||
|
@ -9,7 +9,8 @@
|
||||
|
||||
TCA9548 MP(0x70);
|
||||
|
||||
uint8_t searchAddress = 0x38; // dummy, adjust to your needs.
|
||||
// 0x38 is a dummy (in fact a PCF8574), adjust to your needs.
|
||||
uint8_t searchAddress = 0x38;
|
||||
|
||||
|
||||
void setup()
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
# Data types (KEYWORD1)
|
||||
TCA9548 KEYWORD1
|
||||
PCA9548 KEYWORD1
|
||||
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/TCA9548"
|
||||
},
|
||||
"version": "0.1.6",
|
||||
"version": "0.2.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=TCA9548
|
||||
version=0.1.6
|
||||
version=0.2.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino Library for TCA9548 I2C multiplexer.
|
||||
|
@ -69,14 +69,18 @@ unittest(test_constants)
|
||||
}
|
||||
|
||||
|
||||
unittest(test_begin)
|
||||
unittest(test_constructor)
|
||||
{
|
||||
TCA9548 tca(0x70);
|
||||
|
||||
bool b = tca.begin();
|
||||
assertEqual(b, true);
|
||||
Wire.begin();
|
||||
|
||||
assertTrue(tca.begin());
|
||||
assertTrue(tca.isConnected());
|
||||
|
||||
PCA9548 pca(0x71);
|
||||
assertTrue(pca.begin());
|
||||
assertTrue(pca.isConnected());
|
||||
}
|
||||
|
||||
|
||||
@ -84,6 +88,8 @@ unittest(test_enable)
|
||||
{
|
||||
TCA9548 tca(0x70);
|
||||
|
||||
Wire.begin();
|
||||
|
||||
bool b = tca.begin();
|
||||
assertEqual(b, true);
|
||||
|
||||
@ -103,6 +109,8 @@ unittest(test_select)
|
||||
{
|
||||
TCA9548 tca(0x70);
|
||||
|
||||
Wire.begin();
|
||||
|
||||
bool b = tca.begin();
|
||||
assertEqual(b, true);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user