mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.3.0 TCA9548
This commit is contained in:
parent
82f164b6bb
commit
e906d37ad6
@ -6,11 +6,20 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.3.0] - 2024-04-15
|
||||
- Fix #20, **disableChannel()** bug + optimize.
|
||||
- Fix **isConnected(address, channel)** bug.
|
||||
- update keywords.txt
|
||||
- update readme.md
|
||||
- add **uint8_t find(address)** function, returns mask.
|
||||
- update / add examples.
|
||||
|
||||
----
|
||||
|
||||
## [0.2.2] - 2024-01-01
|
||||
- add **bool isConnected(uint8_t address, uint8_t channel)**
|
||||
- minor edits
|
||||
|
||||
|
||||
## [0.2.1] - 2023-12-09
|
||||
- add derived classes
|
||||
- PCA9543 (2 channel), PCA9545 (4 channel), PCA9546 (4 channel)
|
||||
|
@ -99,9 +99,6 @@ There are however small differences, check the data sheets to see the details.
|
||||
deviceAddress = 0x70 .. 0x77, wire = Wire or WireN.
|
||||
- **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.
|
||||
- **bool isConnected(uint8_t address, uint8_t channel)** find address on selected channel.
|
||||
Note that this changes the selected and or enabled channels.
|
||||
Returns true if found.
|
||||
|
||||
The derived classes PCA9548/PCA9546 have the same interface, except constructor.
|
||||
(see #15)
|
||||
@ -114,9 +111,17 @@ The derived classes PCA9548/PCA9546 have the same interface, except constructor.
|
||||
|
||||
#### Find device
|
||||
|
||||
- **bool isConnected(uint8_t address)** returns true if arbitrary address is found on I2C bus.
|
||||
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.
|
||||
- **bool isConnected(uint8_t address)** returns true if arbitrary address is found on the
|
||||
current I2C bus + selected channels.
|
||||
This can be used to verify if a certain device is available (or not) on any **enabled** channel.
|
||||
So it does not scan all (8) channels to see if any of them has a device with the address given.
|
||||
- **bool isConnected(uint8_t address, uint8_t channel)** find address on selected channel.
|
||||
Note that this function changes the selected and or enabled channels.
|
||||
Returns true if found.
|
||||
- **uint8_t find(uint8_t address)** returns a mask with bits set for channels
|
||||
where the address is found. It scans all channels available.
|
||||
Note that this function changes the selected and or enabled channels.
|
||||
Returns 0 when the address is not found on any channel, or one bit set per channel found.
|
||||
|
||||
|
||||
#### Channel functions
|
||||
@ -145,9 +150,10 @@ 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.
|
||||
- **int getError()** returns the last (I2C) status / error.
|
||||
|
||||
|
||||
#### Forced IO
|
||||
@ -155,7 +161,8 @@ Optional the library can reset the device.
|
||||
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.
|
||||
Note that writes are only optimized if the channels are already set.
|
||||
Forced IO is also used to speed up **getChannelMask()**.
|
||||
|
||||
- **void setForced(bool forced = false)** set forced write, slower but more robust.
|
||||
- forced == false == fast mode (default).
|
||||
@ -165,6 +172,8 @@ Note that writes are only optimized if the channels are already set.
|
||||
|
||||
#### Interrupts
|
||||
|
||||
(not tested)
|
||||
|
||||
The PCA9545 and PCA9543 support interrupts.
|
||||
These two derived classes have implemented the
|
||||
|
||||
@ -200,6 +209,10 @@ Not implemented yet, preparation for future.
|
||||
- set an "always enabled" mask.
|
||||
- investigate the consequences!
|
||||
- extend the unit tests.
|
||||
- **uint8_t find(address)** returns a mask of channel where address is found
|
||||
- restore channel in **isConnected(address, channel);
|
||||
- add guard in **reset()**, is the pin set?
|
||||
|
||||
|
||||
#### Wont
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: TCA9548.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.2
|
||||
// VERSION: 0.3.0
|
||||
// DATE: 2021-03-16
|
||||
// PURPOSE: Arduino Library for TCA9548 I2C multiplexer and compatibles.
|
||||
|
||||
@ -45,7 +45,20 @@ bool TCA9548::isConnected(uint8_t address)
|
||||
bool TCA9548::isConnected(uint8_t address, uint8_t channel)
|
||||
{
|
||||
if (!selectChannel(channel)) return false;
|
||||
return isConnected(_address);
|
||||
return isConnected(address);
|
||||
}
|
||||
|
||||
|
||||
uint8_t TCA9548::find(uint8_t address)
|
||||
{
|
||||
uint8_t mask = 0x00;
|
||||
for (uint8_t ch = 0; ch < _channels; ch++)
|
||||
{
|
||||
// will work partially if MP is off line (by choice).
|
||||
selectChannel(ch);
|
||||
if (isConnected(address)) mask |= (1 << ch);
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
|
||||
@ -58,30 +71,21 @@ uint8_t TCA9548::channelCount()
|
||||
bool TCA9548::enableChannel(uint8_t channel)
|
||||
{
|
||||
if (channel >= _channels) return false;
|
||||
if (!isEnabled(channel))
|
||||
{
|
||||
setChannelMask(_mask | (0x01 << channel));
|
||||
}
|
||||
return true;
|
||||
return setChannelMask(_mask | (0x01 << channel));
|
||||
}
|
||||
|
||||
|
||||
bool TCA9548::disableChannel(uint8_t channel)
|
||||
{
|
||||
if (channel >= _channels) return false;
|
||||
if (!isEnabled(channel))
|
||||
{
|
||||
setChannelMask(_mask & ~(0x01 << channel));
|
||||
}
|
||||
return true;
|
||||
return setChannelMask(_mask & ~(0x01 << channel));
|
||||
}
|
||||
|
||||
|
||||
bool TCA9548::selectChannel(uint8_t channel)
|
||||
{
|
||||
if (channel >= _channels) return false;
|
||||
setChannelMask(0x01 << channel);
|
||||
return true;
|
||||
return setChannelMask(0x01 << channel);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: TCA9548.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.2
|
||||
// VERSION: 0.3.0
|
||||
// DATE: 2021-03-16
|
||||
// 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.2"))
|
||||
#define TCA9548_LIB_VERSION (F("0.3.0"))
|
||||
|
||||
|
||||
// ERROR CODES (to be elaborated)
|
||||
@ -33,6 +33,8 @@ public:
|
||||
bool isConnected(uint8_t address); // find any address on I2C bus
|
||||
bool isConnected(uint8_t address, uint8_t channel); // find address on selected channel
|
||||
|
||||
uint8_t find(uint8_t address); // returns a mask with channels
|
||||
|
||||
// channel = 0..channelCount()-1
|
||||
uint8_t channelCount();
|
||||
bool enableChannel(uint8_t channel); // enable this channel non exclusive
|
||||
@ -61,13 +63,13 @@ public:
|
||||
|
||||
|
||||
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; // PCA954x support.
|
||||
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; // PCA954x support.
|
||||
};
|
||||
|
||||
|
||||
|
52
libraries/TCA9548/examples/TCA9548_find/TCA9548_find.ino
Normal file
52
libraries/TCA9548/examples/TCA9548_find/TCA9548_find.ino
Normal file
@ -0,0 +1,52 @@
|
||||
//
|
||||
// FILE: TCA9548_find.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 TO MULTIPLEXER");
|
||||
}
|
||||
|
||||
channels = MP.channelCount();
|
||||
Serial.print("CHAN:\t");
|
||||
Serial.println(MP.channelCount());
|
||||
|
||||
// adjust address range to your needs.
|
||||
for (uint8_t addr = 60; addr < 70; addr++)
|
||||
{
|
||||
if (addr % 10 == 0) Serial.println();
|
||||
Serial.print(addr);
|
||||
Serial.print("\t");
|
||||
Serial.print(MP.find(addr), BIN);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
Serial.println("done...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// FILE: tca9548_demo.ino
|
||||
// FILE: TCA9548_demo.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo TCA9548 I2C multiplexer
|
||||
// URL: https://github.com/RobTillaart/TCA9548
|
||||
|
@ -1,8 +1,10 @@
|
||||
//
|
||||
// FILE: tca9548_search_device.ino
|
||||
// FILE: TCA9548_search_device.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo TCA9548 I2C multiplexer
|
||||
// URL: https://github.com/RobTillaart/TCA9548
|
||||
//
|
||||
// NOTE: since 0.3.0 a find function is added.
|
||||
|
||||
|
||||
#include "TCA9548.h"
|
||||
@ -28,7 +30,7 @@ void setup()
|
||||
}
|
||||
|
||||
Serial.println("\nScan the channels of the multiplexer for searchAddress.\n");
|
||||
for (int chan = 0; chan < 8; chan++)
|
||||
for (int chan = 0; chan < MP.channelCount(); chan++)
|
||||
{
|
||||
MP.selectChannel(chan);
|
||||
bool b = MP.isConnected(searchAddress);
|
||||
|
@ -11,7 +11,9 @@ PCA9543 KEYWORD1
|
||||
# Methods and Functions (KEYWORD2)
|
||||
begin KEYWORD2
|
||||
isConnected KEYWORD2
|
||||
find KEYWORD2
|
||||
|
||||
channelCount KEYWORD2
|
||||
enableChannel KEYWORD2
|
||||
disableChannel KEYWORD2
|
||||
selectChannel KEYWORD2
|
||||
@ -29,6 +31,8 @@ getForced KEYWORD2
|
||||
|
||||
getError KEYWORD2
|
||||
|
||||
|
||||
# Devices with interrupt
|
||||
getInterruptMask KEYWORD2
|
||||
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/TCA9548"
|
||||
},
|
||||
"version": "0.2.2",
|
||||
"version": "0.3.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=TCA9548
|
||||
version=0.2.2
|
||||
version=0.3.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino Library for TCA9548 I2C multiplexer and compatibles.
|
||||
|
Loading…
Reference in New Issue
Block a user