0.1.5 TCA9548

This commit is contained in:
rob tillaart 2023-02-12 14:15:22 +01:00
parent 3d42b11e80
commit b5e840a6d3
9 changed files with 112 additions and 27 deletions

View File

@ -6,6 +6,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.5] - 2023-02-12
- fix #8 ambiguity
- update keywords.txt
- add example **tca9548_search_device.ino**
- update readme.md
- prepare error handling (constants)
- some minor edits.
## [0.1.4] - 2023-01-23
- update GitHub actions
- update license 2023
@ -15,7 +24,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- all channel functions return bool, true on success.
- minor edits
## [0.1.3] - 2022-11-26
- Add RP2040 support to build-CI.
- Add CHANGELOG.md

View File

@ -40,7 +40,7 @@ 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 datasheets to see the details.
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
@ -100,32 +100,42 @@ Note that writes are only optimized if the channels are already set.
- **void setForced(bool forced = false)** set forced write, slower but more robust.
- forced == false == fast mode (default).
- forced == true == robust mode.
- forced == true == slower, robust mode.
- **bool getForced()** returns set flag.
## Error Codes
Not implemented yet, preparation for 0.2.0.
| 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
- improve documentation.
- improve error handling
- improve error handling.
#### Should
- add examples
- test test and test
- write unit test
- create derived classes for compatible devices
- add examples.
- test test and test.
- write unit test.
- create derived classes for compatible devices (0.2.0).
- see above PCA9548 and PCA9548a.
- **bool isConnected(channel, address)** (0.2.0)
- keep previous mask?
#### Could
- set an "always enabled" mask (have to investigate the consequences)
- verify channel in range
- e.g. **bool enableChannel(uint8_t channel)**, disable(), select()
- set an "always enabled" mask.
- investigate the consequences!
#### Wont

View File

@ -1,7 +1,7 @@
//
// FILE: TCA9548.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.4
// VERSION: 0.1.5
// DATE: 2021-03-16
// PURPOSE: Library for TCA9548 I2C multiplexer
@ -16,7 +16,7 @@ TCA9548::TCA9548(const uint8_t deviceAddress, TwoWire *wire)
_mask = 0x00;
_resetPin = -1;
_forced = false;
_error = 0;
_error = TCA9548_OK;
}
@ -118,7 +118,7 @@ uint8_t TCA9548::getChannelMask()
{
if (_forced) // read from device.
{
_wire->requestFrom(_address, 1);
_wire->requestFrom(_address, (uint8_t)1);
_mask = _wire->read();
}
return _mask;
@ -156,7 +156,7 @@ bool TCA9548::getForced()
int TCA9548::getError()
{
int error = _error;
_error = 0;
_error = TCA9548_OK;
return error;
}

View File

@ -2,7 +2,7 @@
//
// FILE: TCA9548.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.4
// VERSION: 0.1.5
// DATE: 2021-03-16
// PURPOSE: Library for TCA9548 I2C multiplexer
// URL: https://github.com/RobTillaart/TCA9548
@ -12,7 +12,14 @@
#include "Wire.h"
#define TCA9548_LIB_VERSION (F("0.1.4"))
#define TCA9548_LIB_VERSION (F("0.1.5"))
// ERROR CODES (to be elaborated)
#define TCA9548_OK 0
#define TCA9548_ERROR_I2C -10 // not used yet
#define TCA9548_ERROR_CHANNEL -20 // not used yet
class TCA9548

View File

@ -0,0 +1,49 @@
//
// FILE: tca9548_search_device.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo TCA9548 I2C multiplexer
// URL: https://github.com/RobTillaart/TCA9548
#include "TCA9548.h"
TCA9548 MP(0x70);
uint8_t searchAddress = 0x38; // dummy, adjust to your needs.
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.println();
Wire.begin();
if (MP.begin() == false)
{
Serial.println("Could not connect to TCA9548 multiplexer.");
}
Serial.println("\nScan the channels of the multiplexer for searchAddress.\n");
for (int chan = 0; chan < 8; chan++)
{
MP.selectChannel(chan);
bool b = MP.isConnected(searchAddress);
Serial.print("CHAN: ");
Serial.print(chan);
Serial.print("\t");
Serial.print( b ? "found!" : "x");
}
Serial.println();
Serial.println("done...");
}
void loop()
{
}
// -- END OF FILE --

View File

@ -12,6 +12,7 @@ enableChannel KEYWORD2
disableChannel KEYWORD2
selectChannel KEYWORD2
isEnabled KEYWORD2
disableAllChannels KEYWORD2
setChannelMask KEYWORD2
getChannelMask KEYWORD2
@ -28,3 +29,4 @@ getError KEYWORD2
# Constants (LITERAL1)
TCA9548_LIB_VERSION LITERAL1
TCA9548_OK LITERAL1

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/TCA9548"
},
"version": "0.1.4",
"version": "0.1.5",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=TCA9548
version=0.1.4
version=0.1.5
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino Library for TCA9548 I2C multiplexer.

View File

@ -61,6 +61,14 @@ unittest_teardown()
}
unittest(test_constants)
{
assertEqual(0, TCA9548_OK);
assertEqual(-10, TCA9548_ERROR_I2C);
assertEqual(-20, TCA9548_ERROR_CHANNEL);
}
unittest(test_begin)
{
TCA9548 tca(0x70);
@ -69,7 +77,6 @@ unittest(test_begin)
assertEqual(b, true);
assertTrue(tca.isConnected());
}
@ -113,4 +120,6 @@ unittest(test_select)
unittest_main()
// -- END OF FILE --