mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.2.1 TCA9548
This commit is contained in:
parent
6d0c7713cd
commit
fc83b82d66
@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.2.1] - 2023-12-09
|
||||
- add derived classes
|
||||
- PCA9543 (2 channel), PCA9545 (4 channel), PCA9546 (4 channel)
|
||||
- add **uint8_t getInterruptMask()**
|
||||
- fix begin() : remove wire-> begin() as dependency should be outside lib
|
||||
- fix readme.md
|
||||
|
||||
|
||||
## [0.2.0] - 2023-12-09
|
||||
- refactor API, begin()
|
||||
- update readme.md
|
||||
|
@ -11,25 +11,42 @@
|
||||
|
||||
# TCA9548
|
||||
|
||||
Arduino Library for TCA9548 I2C multiplexer.
|
||||
Arduino Library for TCA9548 I2C multiplexer and compatibles.
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
Library for the TCA9548 and TCA9548a (PCA9548, PCA9548a) I2C multiplexer.
|
||||
Library for the TCA9548 and TCA9548a 8 channel I2C multiplexer.
|
||||
|
||||
The library allows you to enable 0 to 7 I2C channels (ports) uniquely or simultaneously.
|
||||
This is especially useful if you have multiple devices/sensors that have a fixed address,
|
||||
or you have address conflicts between I2C devices
|
||||
Compatible with PCA9548, PCA9548a, PCA9546, PCA9545, PCA9543.
|
||||
|
||||
The library allows you to enable 0 to 7 I2C channels (SDA + SCL) uniquely or simultaneously.
|
||||
In fact the TCA9548 is therefore a **switch**, although often named a multiplexer.
|
||||
A multiplexer is useful if you have
|
||||
- multiple identical devices that have a fixed address,
|
||||
- a too small address range or
|
||||
- if there are address conflicts between different I2C devices.
|
||||
|
||||
The library caches the channels enabled, and if a channel is enabled,
|
||||
it will not be enabled again (low level) to optimize performance.
|
||||
|
||||
The device works with 2.3 V to 5.5 V so it should work with most MCU's.
|
||||
|
||||
**Warning**
|
||||
The library is not tested extensively.
|
||||
|
||||
I2C address of the device itself is 0x70 .. 0x77.
|
||||
This address may not be used on any of the I2C channels of course.
|
||||
|
||||
The library caches the channels enabled, and if a channel is enabled,
|
||||
it will not be enabled again (low level) to optimize performance.
|
||||
#### I2C
|
||||
|
||||
I2C address of the device itself is 0x70 .. 0x77.
|
||||
This address can not be used on any of the I2C channels of course.
|
||||
|
||||
Note if your first multiplexer is 0x70, you may have an array of 0x71 multiplexers behind it.
|
||||
(This will give 8 x 8 = 64 I2C buses, a lot of admin overhead and probably performance penalties).
|
||||
|
||||
Pull-up resistors are required on all upstream and downstream channels.
|
||||
|
||||
The TCA9548 can work up to 400 KHz according to the datasheet.
|
||||
|
||||
|
||||
#### 0.2.0 Breaking change
|
||||
@ -38,20 +55,23 @@ 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()**.
|
||||
before calling the TCA9548 **begin()**.
|
||||
|
||||
|
||||
#### Compatible devices
|
||||
|
||||
This library is expected to work for the PCA9548(a) too as the TCA is pin compatible newer version.
|
||||
This library is expected to work for the following devices: (since 0.2.1)
|
||||
|
||||
| Device | Tested | Notes |
|
||||
|:-----------|:--------:|:-------:|
|
||||
| TCA9548s | n |
|
||||
| PCA9548 | n | see links below |
|
||||
| PCA9548a | n |
|
||||
| device | address | channel | interrupt | reset | verified | notes |
|
||||
|:---------:|:---------:|:---------:|:-----------:|:-------:|:----------:|:-------:|
|
||||
| PCA9543 | 4 | 2 | Y | Y | N |
|
||||
| PCA9545 | 4 | 4 | Y | Y | N |
|
||||
| PCA9546 | 8 | 4 | | Y | N |
|
||||
| PCA9548 | 8 | 8 | | Y | N | equals TCA9648
|
||||
| PCA9548 | 8 | 8 | | Y | N | equals TCA9648
|
||||
|
||||
|
||||
Note: these are not tested with hardware yet, please share your experiences.
|
||||
|
||||
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)
|
||||
@ -59,7 +79,6 @@ There are however small differences, check the data sheets to see the details.
|
||||
- https://www.nxp.com/docs/en/application-note/AN262.pdf
|
||||
|
||||
|
||||
|
||||
#### Related
|
||||
|
||||
- https://github.com/RobTillaart/HC4051 (1x8 mux)
|
||||
@ -78,52 +97,62 @@ There are however small differences, check the data sheets to see the details.
|
||||
|
||||
- **TCA9548(const uint8_t deviceAddress, TwoWire \*wire = &Wire)** Constructor.
|
||||
deviceAddress = 0x70 .. 0x77, wire = Wire or WireN.
|
||||
- **bool begin(uint8_t dataPin, uint8_t clockPin, uint8_t mask = 0x00)** Set I2C pins for ESP32.
|
||||
Set mask of channels to be enabled, default all disabled.
|
||||
- **bool begin(uint8_t mask = 0x00)** 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.
|
||||
The derived classes PCA9548/PCA9546 have the same interface, except constructor.
|
||||
(see #15)
|
||||
|
||||
- **PCA9548(const uint8_t deviceAddress, TwoWire \*wire = &Wire)** Constructor.
|
||||
deviceAddress = 0x70 .. 0x77, wire = Wire or WireN.
|
||||
- **PCA9546(const uint8_t deviceAddress, TwoWire \*wire = &Wire)** Constructor.
|
||||
- **PCA9545(const uint8_t deviceAddress, TwoWire \*wire = &Wire)** Constructor.
|
||||
- **PCA9543(const uint8_t deviceAddress, TwoWire \*wire = &Wire)** Constructor.
|
||||
|
||||
|
||||
#### Find device
|
||||
|
||||
- **bool isConnected(uint8_t address)** returns true if arbitrary address is found on I2C bus.
|
||||
This can be used to verify a certain device is available (or not) on an enabled channel.
|
||||
This can be used to verify if a certain device is available (or not) on an **enabled** channel.
|
||||
So it does not scan all 8 channels to see if any of them has a device with the address given.
|
||||
|
||||
|
||||
#### Channel functions
|
||||
|
||||
All "channel functions" return true on success.
|
||||
|
||||
- **bool enableChannel(uint8_t channel)** enables channel 0 .. 7 non-exclusive.
|
||||
- **bool enableChannel(uint8_t channel)** enables channel 0 .. 7 **non-exclusive**.
|
||||
Multiple channels can be enabled in parallel.
|
||||
- **bool disableChannel(uint8_t channel)** disables channel 0 .. 7.
|
||||
Will not disable other channels.
|
||||
- **bool selectChannel(uint8_t channel)** enables a single channel 0 .. 7 exclusive.
|
||||
- **bool selectChannel(uint8_t channel)** enables a single channel 0 .. 7 **exclusive**.
|
||||
All other channels will be disabled in the same call, so not before or after.
|
||||
- **bool isEnabled(uint8_t channel)** returns true if the channel is enabled.
|
||||
- **bool disableAllChannels()** fast way to disable all.
|
||||
- **bool disableAllChannels()** fast way to disable all channels.
|
||||
|
||||
Multiple channels can also be enabled in one call with a mask.
|
||||
|
||||
- **bool setChannelMask(uint8_t mask)** enables 0 or more channels simultaneously with a bit mask.
|
||||
- **uint8_t getChannelMask()** reads back the bit mask of the channels enabled.
|
||||
|
||||
|
||||
#### Reset
|
||||
|
||||
- **void setResetPin(uint8_t resetPin)** sets the pin to reset the chip. (Not tested)
|
||||
Optional the library can reset the device.
|
||||
|
||||
- **void setResetPin(uint8_t resetPin)** sets the pin to reset the chip.
|
||||
- **void reset()** trigger the reset pin.
|
||||
|
||||
#### Debug
|
||||
|
||||
- **int getError()** returns the last I2C error.
|
||||
|
||||
|
||||
#### Forced IO
|
||||
|
||||
When forced IO is set all writes and read - **getChannelMask()** - will go to the device.
|
||||
If the flag is set to false it will cache the value of the channels enabled.
|
||||
This will result in more responsive / faster calls.
|
||||
When forced IO is set, all writes and read, e.g. **uint8_t getChannelMask()**, will go to the device.
|
||||
If the **forced-IO** flag is set to false, it will cache the value of the channels enabled.
|
||||
This will result in far more responsive and faster calls.
|
||||
Note that writes are only optimized if the channels are already set.
|
||||
|
||||
- **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.
|
||||
- **bool getForced()** returns set flag.
|
||||
|
||||
|
||||
#### Interrupts
|
||||
|
||||
The PCA9545 and PCA9543 support interrupts.
|
||||
These two derived classes have implemented the
|
||||
|
||||
- **uint8_t getInterruptMask()** function that returns a bit mask of interrupts set.
|
||||
|
||||
|
||||
## Error Codes
|
||||
|
||||
Not implemented yet, preparation for 0.2.0.
|
||||
Not implemented yet, preparation for future.
|
||||
|
||||
| name | value | description |
|
||||
|:------------------------|:-------:|:------------------------|
|
||||
| TCA9548_OK | 00 | no error |
|
||||
| TCA9548_OK | 00 | no error |
|
||||
| TCA9548_ERROR_I2C | -10 | detected an I2C error |
|
||||
| TCA9548_ERROR_CHANNEL | -20 | channel out of range |
|
||||
|
||||
|
||||
## 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
|
||||
|
||||
@ -174,17 +191,13 @@ To investigate if these can be made in one derived class tree.
|
||||
#### Should
|
||||
|
||||
- add examples.
|
||||
- test test and test.
|
||||
- write unit test.
|
||||
- create derived classes for compatible devices (0.2.0).
|
||||
- see above PCA9548 and PCA9548a.
|
||||
- investigate support derived classes
|
||||
|
||||
- test with hardware.
|
||||
|
||||
#### Could
|
||||
|
||||
- set an "always enabled" mask.
|
||||
- investigate the consequences!
|
||||
- extend the unit tests.
|
||||
|
||||
#### Wont
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
//
|
||||
// FILE: TCA9548.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.0
|
||||
// VERSION: 0.2.1
|
||||
// DATE: 2021-03-16
|
||||
// PURPOSE: Library for TCA9548 I2C multiplexer
|
||||
// PURPOSE: Arduino Library for TCA9548 I2C multiplexer and compatibles.
|
||||
|
||||
|
||||
#include "TCA9548.h"
|
||||
@ -17,13 +17,12 @@ TCA9548::TCA9548(uint8_t deviceAddress, TwoWire *wire)
|
||||
_resetPin = -1;
|
||||
_forced = false;
|
||||
_error = TCA9548_OK;
|
||||
// _channels = 8;
|
||||
_channels = 8;
|
||||
}
|
||||
|
||||
|
||||
bool TCA9548::begin(uint8_t mask)
|
||||
{
|
||||
_wire->begin();
|
||||
if (! isConnected()) return false;
|
||||
setChannelMask(mask);
|
||||
return true;
|
||||
@ -32,8 +31,7 @@ bool TCA9548::begin(uint8_t mask)
|
||||
|
||||
bool TCA9548::isConnected()
|
||||
{
|
||||
_wire->beginTransmission(_address);
|
||||
return ( _wire->endTransmission() == 0);
|
||||
return isConnected(_address);
|
||||
}
|
||||
|
||||
|
||||
@ -44,10 +42,15 @@ bool TCA9548::isConnected(uint8_t address)
|
||||
}
|
||||
|
||||
|
||||
uint8_t TCA9548::channelCount()
|
||||
{
|
||||
return _channels;
|
||||
}
|
||||
|
||||
|
||||
bool TCA9548::enableChannel(uint8_t channel)
|
||||
{
|
||||
if (channel > 7) return false;
|
||||
if (channel >= _channels) return false;
|
||||
if (!isEnabled(channel))
|
||||
{
|
||||
setChannelMask(_mask | (0x01 << channel));
|
||||
@ -58,7 +61,7 @@ bool TCA9548::enableChannel(uint8_t channel)
|
||||
|
||||
bool TCA9548::disableChannel(uint8_t channel)
|
||||
{
|
||||
if (channel > 7) return false;
|
||||
if (channel >= _channels) return false;
|
||||
if (!isEnabled(channel))
|
||||
{
|
||||
setChannelMask(_mask & ~(0x01 << channel));
|
||||
@ -69,7 +72,7 @@ bool TCA9548::disableChannel(uint8_t channel)
|
||||
|
||||
bool TCA9548::selectChannel(uint8_t channel)
|
||||
{
|
||||
if (channel > 7) return false;
|
||||
if (channel >= _channels) return false;
|
||||
setChannelMask(0x01 << channel);
|
||||
return true;
|
||||
}
|
||||
@ -77,7 +80,7 @@ bool TCA9548::selectChannel(uint8_t channel)
|
||||
|
||||
bool TCA9548::isEnabled(uint8_t channel)
|
||||
{
|
||||
if (channel > 7) return false;
|
||||
if (channel >= _channels) return false;
|
||||
return (_mask & (0x01 << channel));
|
||||
}
|
||||
|
||||
@ -90,7 +93,7 @@ bool TCA9548::disableAllChannels()
|
||||
|
||||
bool TCA9548::setChannelMask(uint8_t mask)
|
||||
{
|
||||
if ((_mask == mask) && (! _forced)) return true;
|
||||
if ((_mask == mask) && (not _forced)) return true;
|
||||
_mask = mask;
|
||||
_wire->beginTransmission(_address);
|
||||
_wire->write(_mask);
|
||||
@ -148,10 +151,87 @@ int TCA9548::getError()
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DERIVED CLASS
|
||||
// PCA9548
|
||||
//
|
||||
PCA9548::PCA9548(uint8_t deviceAddress, TwoWire *wire) : TCA9548(deviceAddress, wire)
|
||||
{
|
||||
_channels = 8;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PCA9546
|
||||
//
|
||||
PCA9546::PCA9546(uint8_t deviceAddress, TwoWire *wire) : TCA9548(deviceAddress, wire)
|
||||
{
|
||||
_channels = 4;
|
||||
}
|
||||
|
||||
uint8_t PCA9546::getChannelMask()
|
||||
{
|
||||
if (_forced) // read from device.
|
||||
{
|
||||
_wire->requestFrom(_address, (uint8_t)1);
|
||||
_mask = _wire->read();
|
||||
}
|
||||
return _mask &= 0x0F;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PCA9545
|
||||
//
|
||||
PCA9545::PCA9545(uint8_t deviceAddress, TwoWire *wire) : TCA9548(deviceAddress, wire)
|
||||
{
|
||||
_channels = 4;
|
||||
}
|
||||
|
||||
uint8_t PCA9545::getChannelMask()
|
||||
{
|
||||
if (_forced) // read from device.
|
||||
{
|
||||
_wire->requestFrom(_address, (uint8_t)1);
|
||||
_mask = _wire->read();
|
||||
}
|
||||
return _mask &= 0x0F;
|
||||
}
|
||||
|
||||
uint8_t PCA9545::getInterruptMask()
|
||||
{
|
||||
_wire->requestFrom(_address, (uint8_t)1);
|
||||
uint8_t mask = _wire->read();
|
||||
mask >>= 4;
|
||||
return mask;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PCA9548
|
||||
//
|
||||
PCA9543::PCA9543(uint8_t deviceAddress, TwoWire *wire) : TCA9548(deviceAddress, wire)
|
||||
{
|
||||
_channels = 2;
|
||||
}
|
||||
|
||||
uint8_t PCA9543::getChannelMask()
|
||||
{
|
||||
if (_forced) // read from device.
|
||||
{
|
||||
_wire->requestFrom(_address, (uint8_t)1);
|
||||
_mask = _wire->read();
|
||||
}
|
||||
return _mask &= 0x03;
|
||||
}
|
||||
|
||||
uint8_t PCA9543::getInterruptMask()
|
||||
{
|
||||
_wire->requestFrom(_address, (uint8_t)1);
|
||||
uint8_t mask = _wire->read();
|
||||
mask >>= 4;
|
||||
return mask;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,9 +2,9 @@
|
||||
//
|
||||
// FILE: TCA9548.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.0
|
||||
// VERSION: 0.2.1
|
||||
// DATE: 2021-03-16
|
||||
// PURPOSE: Library for TCA9548 I2C multiplexer
|
||||
// PURPOSE: Arduino Library for TCA9548 I2C multiplexer and compatibles.
|
||||
// URL: https://github.com/RobTillaart/TCA9548
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
#include "Wire.h"
|
||||
|
||||
|
||||
#define TCA9548_LIB_VERSION (F("0.2.0"))
|
||||
#define TCA9548_LIB_VERSION (F("0.2.1"))
|
||||
|
||||
|
||||
// ERROR CODES (to be elaborated)
|
||||
@ -32,15 +32,20 @@ public:
|
||||
bool isConnected(); // find multiplexer on I2C bus
|
||||
bool isConnected(uint8_t address); // find any address on I2C bus
|
||||
|
||||
// channel = 0.. 7
|
||||
|
||||
// channel = 0..channelCount()-1
|
||||
uint8_t channelCount();
|
||||
bool enableChannel(uint8_t channel); // enable this channel non exclusive
|
||||
bool disableChannel(uint8_t channel);
|
||||
bool selectChannel(uint8_t channel); // enable only this channel
|
||||
bool isEnabled(uint8_t channel);
|
||||
bool disableAllChannels();
|
||||
|
||||
|
||||
// mask = 0x00 .. 0xFF - every bit is a channel.
|
||||
// note these are set simultaneously.
|
||||
// although not for derived types.
|
||||
// note 1: these are set simultaneously.
|
||||
// note 2: these may include interrupt bits (in derived classes)
|
||||
bool setChannelMask(uint8_t mask);
|
||||
uint8_t getChannelMask();
|
||||
|
||||
@ -62,7 +67,7 @@ protected:
|
||||
uint8_t _resetPin; // default not set == -1 (255)
|
||||
bool _forced;
|
||||
int _error;
|
||||
// uint8_t _channels; // future PCA954x support.
|
||||
uint8_t _channels; // PCA954x support.
|
||||
};
|
||||
|
||||
|
||||
@ -70,6 +75,10 @@ protected:
|
||||
//
|
||||
// DERIVED CLASS
|
||||
//
|
||||
// see - https://github.com/RobTillaart/TCA9548/issues/15
|
||||
//
|
||||
|
||||
// SWITCH, 8 channel + reset
|
||||
class PCA9548 : public TCA9548
|
||||
{
|
||||
public:
|
||||
@ -77,5 +86,36 @@ public:
|
||||
};
|
||||
|
||||
|
||||
// SWITCH, 4 channel + reset
|
||||
class PCA9546 : public TCA9548
|
||||
{
|
||||
public:
|
||||
PCA9546(uint8_t deviceAddress, TwoWire *wire = &Wire);
|
||||
uint8_t getChannelMask();
|
||||
};
|
||||
|
||||
|
||||
// DEVICES WITH INTERRUPT
|
||||
|
||||
// SWITCH, 4 channel + reset + interrupt
|
||||
class PCA9545 : public TCA9548
|
||||
{
|
||||
public:
|
||||
PCA9545(uint8_t deviceAddress, TwoWire *wire = &Wire);
|
||||
uint8_t getChannelMask();
|
||||
uint8_t getInterruptMask();
|
||||
};
|
||||
|
||||
|
||||
// SWITCH, 2 channel + reset + interrupt
|
||||
class PCA9543 : public TCA9548
|
||||
{
|
||||
public:
|
||||
PCA9543(uint8_t deviceAddress, TwoWire *wire = &Wire);
|
||||
uint8_t getChannelMask();
|
||||
uint8_t getInterruptMask();
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
76
libraries/TCA9548/examples/PCA9543_demo/PCA9543_demo.ino
Normal file
76
libraries/TCA9548/examples/PCA9543_demo/PCA9543_demo.ino
Normal file
@ -0,0 +1,76 @@
|
||||
//
|
||||
// FILE: PCA9543_demo.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo PCA9543 I2C multiplexer
|
||||
// URL: https://github.com/RobTillaart/TCA9548
|
||||
|
||||
|
||||
#include "TCA9548.h"
|
||||
|
||||
PCA9543 MP(0x70);
|
||||
|
||||
uint8_t channels = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("TCA9548_LIB_VERSION: ");
|
||||
Serial.println(TCA9548_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
if (MP.begin() == false)
|
||||
{
|
||||
Serial.println("COULD NOT CONNECT");
|
||||
}
|
||||
|
||||
channels = MP.channelCount();
|
||||
Serial.print("CHAN:\t");
|
||||
Serial.println(MP.channelCount());
|
||||
|
||||
Serial.print("MASK:\t");
|
||||
Serial.println(MP.getChannelMask(), HEX);
|
||||
for (int chan = 0; chan < channels; chan++)
|
||||
{
|
||||
Serial.print("PRE:\t");
|
||||
Serial.print(MP.isEnabled(chan));
|
||||
MP.enableChannel(chan);
|
||||
Serial.print("\t");
|
||||
Serial.println(MP.isEnabled(chan));
|
||||
delay(100);
|
||||
}
|
||||
Serial.println();
|
||||
MP.setChannelMask(0x00);
|
||||
|
||||
Serial.print("MASK:\t");
|
||||
Serial.println(MP.getChannelMask(), HEX);
|
||||
for (int chan = 0; chan < channels; chan++)
|
||||
{
|
||||
MP.enableChannel(chan);
|
||||
|
||||
Serial.print("MASK:\t");
|
||||
Serial.println(MP.getChannelMask(), HEX);
|
||||
delay(100);
|
||||
}
|
||||
for (int chan = 0; chan < channels; chan++)
|
||||
{
|
||||
MP.disableChannel(chan);
|
||||
Serial.print("MASK:\t");
|
||||
Serial.println(MP.getChannelMask(), HEX);
|
||||
delay(100);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
Serial.println("done...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
77
libraries/TCA9548/examples/PCA9545_demo/PCA9545_demo.ino
Normal file
77
libraries/TCA9548/examples/PCA9545_demo/PCA9545_demo.ino
Normal file
@ -0,0 +1,77 @@
|
||||
//
|
||||
// FILE: tca9548_demo.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo TCA9548 I2C multiplexer
|
||||
// URL: https://github.com/RobTillaart/TCA9548
|
||||
|
||||
|
||||
#include "TCA9548.h"
|
||||
|
||||
TCA9548 MP(0x70);
|
||||
|
||||
uint8_t channels = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("TCA9548_LIB_VERSION: ");
|
||||
Serial.println(TCA9548_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
if (MP.begin() == false)
|
||||
{
|
||||
Serial.println("COULD NOT CONNECT");
|
||||
}
|
||||
|
||||
channels = MP.channelCount();
|
||||
Serial.print("CHAN:\t");
|
||||
Serial.println(MP.channelCount());
|
||||
|
||||
Serial.print("MASK:\t");
|
||||
Serial.println(MP.getChannelMask(), HEX);
|
||||
for (int chan = 0; chan < channels; chan++)
|
||||
{
|
||||
Serial.print("PRE:\t");
|
||||
Serial.print(MP.isEnabled(chan));
|
||||
MP.enableChannel(chan);
|
||||
Serial.print("\t");
|
||||
Serial.println(MP.isEnabled(chan));
|
||||
delay(100);
|
||||
}
|
||||
Serial.println();
|
||||
MP.setChannelMask(0x00);
|
||||
|
||||
Serial.print("MASK:\t");
|
||||
Serial.println(MP.getChannelMask(), HEX);
|
||||
for (int chan = 0; chan < channels; chan++)
|
||||
{
|
||||
MP.enableChannel(chan);
|
||||
|
||||
Serial.print("MASK:\t");
|
||||
Serial.println(MP.getChannelMask(), HEX);
|
||||
delay(100);
|
||||
}
|
||||
for (int chan = 0; chan < channels; chan++)
|
||||
{
|
||||
MP.disableChannel(chan);
|
||||
Serial.print("MASK:\t");
|
||||
Serial.println(MP.getChannelMask(), HEX);
|
||||
delay(100);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
Serial.println("done...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
76
libraries/TCA9548/examples/PCA9546_demo/PCA9546_demo.ino
Normal file
76
libraries/TCA9548/examples/PCA9546_demo/PCA9546_demo.ino
Normal file
@ -0,0 +1,76 @@
|
||||
//
|
||||
// FILE: PCA9546_demo.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo PCA9546 I2C multiplexer
|
||||
// URL: https://github.com/RobTillaart/TCA9548
|
||||
|
||||
|
||||
#include "TCA9548.h"
|
||||
|
||||
PCA9546 MP(0x70);
|
||||
|
||||
uint8_t channels = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("TCA9548_LIB_VERSION: ");
|
||||
Serial.println(TCA9548_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
if (MP.begin() == false)
|
||||
{
|
||||
Serial.println("COULD NOT CONNECT");
|
||||
}
|
||||
|
||||
channels = MP.channelCount();
|
||||
Serial.print("CHAN:\t");
|
||||
Serial.println(MP.channelCount());
|
||||
|
||||
Serial.print("MASK:\t");
|
||||
Serial.println(MP.getChannelMask(), HEX);
|
||||
for (int chan = 0; chan < channels; chan++)
|
||||
{
|
||||
Serial.print("PRE:\t");
|
||||
Serial.print(MP.isEnabled(chan));
|
||||
MP.enableChannel(chan);
|
||||
Serial.print("\t");
|
||||
Serial.println(MP.isEnabled(chan));
|
||||
delay(100);
|
||||
}
|
||||
Serial.println();
|
||||
MP.setChannelMask(0x00);
|
||||
|
||||
Serial.print("MASK:\t");
|
||||
Serial.println(MP.getChannelMask(), HEX);
|
||||
for (int chan = 0; chan < channels; chan++)
|
||||
{
|
||||
MP.enableChannel(chan);
|
||||
|
||||
Serial.print("MASK:\t");
|
||||
Serial.println(MP.getChannelMask(), HEX);
|
||||
delay(100);
|
||||
}
|
||||
for (int chan = 0; chan < channels; chan++)
|
||||
{
|
||||
MP.disableChannel(chan);
|
||||
Serial.print("MASK:\t");
|
||||
Serial.println(MP.getChannelMask(), HEX);
|
||||
delay(100);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
Serial.println("done...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -9,11 +9,15 @@
|
||||
|
||||
TCA9548 MP(0x70);
|
||||
|
||||
uint8_t channels = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("TCA9548_LIB_VERSION: ");
|
||||
Serial.println(TCA9548_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
@ -22,9 +26,13 @@ void setup()
|
||||
Serial.println("COULD NOT CONNECT");
|
||||
}
|
||||
|
||||
channels = MP.channelCount();
|
||||
Serial.print("CHAN:\t");
|
||||
Serial.println(MP.channelCount());
|
||||
|
||||
Serial.print("MASK:\t");
|
||||
Serial.println(MP.getChannelMask(), HEX);
|
||||
for (int chan = 0; chan < 8; chan++)
|
||||
for (int chan = 0; chan < channels; chan++)
|
||||
{
|
||||
Serial.print("PRE:\t");
|
||||
Serial.print(MP.isEnabled(chan));
|
||||
@ -38,7 +46,7 @@ void setup()
|
||||
|
||||
Serial.print("MASK:\t");
|
||||
Serial.println(MP.getChannelMask(), HEX);
|
||||
for (int chan = 0; chan < 8; chan++)
|
||||
for (int chan = 0; chan < channels; chan++)
|
||||
{
|
||||
MP.enableChannel(chan);
|
||||
|
||||
@ -46,7 +54,7 @@ void setup()
|
||||
Serial.println(MP.getChannelMask(), HEX);
|
||||
delay(100);
|
||||
}
|
||||
for (int chan = 0; chan < 8; chan++)
|
||||
for (int chan = 0; chan < channels; chan++)
|
||||
{
|
||||
MP.disableChannel(chan);
|
||||
Serial.print("MASK:\t");
|
||||
|
@ -17,6 +17,8 @@ void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("TCA9548_LIB_VERSION: ");
|
||||
Serial.println(TCA9548_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
|
@ -3,6 +3,9 @@
|
||||
# Data types (KEYWORD1)
|
||||
TCA9548 KEYWORD1
|
||||
PCA9548 KEYWORD1
|
||||
PCA9546 KEYWORD1
|
||||
PCA9545 KEYWORD1
|
||||
PCA9543 KEYWORD1
|
||||
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
@ -26,6 +29,8 @@ getForced KEYWORD2
|
||||
|
||||
getError KEYWORD2
|
||||
|
||||
getInterruptMask KEYWORD2
|
||||
|
||||
|
||||
# Constants (LITERAL1)
|
||||
TCA9548_LIB_VERSION LITERAL1
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "TCA9548",
|
||||
"keywords": "TCA9548,TCA9548a,PCA9548,PCA9548a,I2C,multiplexer",
|
||||
"description": "Arduino Library for TCA9548 I2C multiplexer.",
|
||||
"description": "Arduino Library for TCA9548 I2C multiplexer.\nTCA9548a, PCA9548, PCA9548a, PCA9546, PCA9545, PCA9543",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/TCA9548"
|
||||
},
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.1",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
|
@ -1,9 +1,9 @@
|
||||
name=TCA9548
|
||||
version=0.2.0
|
||||
version=0.2.1
|
||||
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
|
||||
sentence=Arduino Library for TCA9548 I2C multiplexer and compatibles.
|
||||
paragraph=TCA9548, TCA9548a, PCA9548, PCA9548a, PCA9546, PCA9545, PCA9543
|
||||
category=Signal Input/Output
|
||||
url=https://github.com/RobTillaart/TCA9548
|
||||
architectures=*
|
||||
|
@ -77,10 +77,27 @@ unittest(test_constructor)
|
||||
|
||||
assertTrue(tca.begin());
|
||||
assertTrue(tca.isConnected());
|
||||
assertEqual(8, tca.channelCount());
|
||||
|
||||
PCA9548 pca(0x71);
|
||||
assertTrue(pca.begin());
|
||||
assertTrue(pca.isConnected());
|
||||
PCA9548 pca8(0x71);
|
||||
assertTrue(pca8.begin());
|
||||
assertTrue(pca8.isConnected());
|
||||
assertEqual(8, pca8.channelCount());
|
||||
|
||||
PCA9546 pca6(0x71);
|
||||
assertTrue(pca6.begin());
|
||||
assertTrue(pca6.isConnected());
|
||||
assertEqual(4, pca6.channelCount());
|
||||
|
||||
PCA9545 pca5(0x71);
|
||||
assertTrue(pca5.begin());
|
||||
assertTrue(pca5.isConnected());
|
||||
assertEqual(4, pca5.channelCount());
|
||||
|
||||
PCA9543 pca3(0x71);
|
||||
assertTrue(pca3.begin());
|
||||
assertTrue(pca3.isConnected());
|
||||
assertEqual(2, pca3.channelCount());
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user