Skip to content

Commit

Permalink
fix #8 ambiguity in call (#9)
Browse files Browse the repository at this point in the history
- fix #8 ambiguity
- update keywords.txt
- add example **tca9548_search_device.ino**
- update readme.md
- prepare error handling (constants)
- some minor edits.
  • Loading branch information
RobTillaart authored Feb 12, 2023
1 parent c8004a8 commit 109849b
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 27 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,12 +24,11 @@ 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
- update readme.md
- move code to .cpp
- move code to .cpp

## [0.1.2] - 2021-12-28
- update license
Expand Down
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions TCA9548.cpp
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -16,7 +16,7 @@ TCA9548::TCA9548(const uint8_t deviceAddress, TwoWire *wire)
_mask = 0x00;
_resetPin = -1;
_forced = false;
_error = 0;
_error = TCA9548_OK;
}


Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -156,7 +156,7 @@ bool TCA9548::getForced()
int TCA9548::getError()
{
int error = _error;
_error = 0;
_error = TCA9548_OK;
return error;
}

Expand Down
13 changes: 10 additions & 3 deletions TCA9548.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -54,7 +61,7 @@ class TCA9548
private:
uint8_t _address;
TwoWire* _wire;
uint8_t _mask; // caching mask = status of channels
uint8_t _mask; // caching mask = status of channels
uint8_t _resetPin; // default not set == -1 (255)
bool _forced;
int _error;
Expand Down
49 changes: 49 additions & 0 deletions examples/tca9548_search_device/tca9548_search_device.ino
Original file line number Diff line number Diff line change
@@ -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 --

2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enableChannel KEYWORD2
disableChannel KEYWORD2
selectChannel KEYWORD2
isEnabled KEYWORD2
disableAllChannels KEYWORD2

setChannelMask KEYWORD2
getChannelMask KEYWORD2
Expand All @@ -28,3 +29,4 @@ getError KEYWORD2
# Constants (LITERAL1)
TCA9548_LIB_VERSION LITERAL1

TCA9548_OK LITERAL1
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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.
paragraph=TCA9548, TCA9548a, PCA9548, PCA9548a
category=Signal Input/Output
url=https://github.com/RobTillaart/TCA9548
architectures=*
includes=TCA9548.h
includes=TCA9548.h
depends=
13 changes: 11 additions & 2 deletions test/unit_test_001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -69,7 +77,6 @@ unittest(test_begin)
assertEqual(b, true);

assertTrue(tca.isConnected());

}


Expand Down Expand Up @@ -113,4 +120,6 @@ unittest(test_select)

unittest_main()

// -- END OF FILE --

// -- END OF FILE --

0 comments on commit 109849b

Please sign in to comment.