class for I2C connection to I2C enabled devices acting as 'slave' devices.
More...
#include <LccNodeI2c.h>
Inherits openlcb::Polling.
|
| bool | begin (const uint8_t bus, const uint8_t addressOffset) |
| | begin Invoked to begin I2C connection, based on the specfied bus and offset. More...
|
| |
| bool | begin (const uint8_t bus, const uint8_t addressOffset, Adafruit_MCP23017 *pMcp) |
| | begin Invoked to begin an MCP (over I2C) connection, based on the specfied bus and offset. More...
|
| |
| bool | begin (const uint8_t bus, const uint8_t addressOffset, FaBoPWM *pPwm) |
| | begin Invoked to begin an PWM (over I2C) connection, based on the specfied bus and offset. More...
|
| |
| bool | send (char *message) |
| | send invoked to send a 'message' to an I2C enabled device, based the I2C bus and address previously configured. More...
|
| |
| bool | get (char *message, const size_t messageLength) |
| | receives character data from I2C enabled device, based the I2C bus and address previously configured. More...
|
| |
| template<typename T > |
| bool | get (T &out) |
| | receives integer data from I2C enabled device, based the I2C bus and address previously configured. More...
|
| |
| Polling * | polling () |
| |
|
| static bool | _isConnected (const uint8_t bus, const uint8_t address, TwoWire *pWire=nullptr) |
| | Check if an I2C device at the given address responds. More...
|
| |
| static TwoWire * | _selectWire (uint8_t bus, TwoWire *pWire=nullptr) |
| | Selects the appropriate TwoWire instance for the given bus. More...
|
| |
| static bool | _initWire (const uint8_t bus, const uint8_t address, TwoWire **ppWire) |
| | begin Invoked to begin an I2C connection, based on the specfied bus and offset. More...
|
| |
class for I2C connection to I2C enabled devices acting as 'slave' devices.
- Note
- The Node hardware device acts as an I2C 'master' device, connecting to one or more slave devices.
Uses Wire.h library to create an I2C connection on hardware bus 0 or 1. Requires an I2C base address to be configured in LccNodeConfig.h and an optional offset to be specified (has to match the offset being used by the I2C enabled device).
- Parameters
-
| addressBase | The I2C device's base address. All I2C devices are idenitified by their base + offset addresses. begin() provides the address offset to be added to the base address. Defaults to 0x20 used by MCP23017 IC. |
Definition at line 65 of file LccNodeI2c.h.
◆ _initWire()
| static bool LccNodeI2c::_initWire |
( |
const uint8_t |
bus, |
|
|
const uint8_t |
address, |
|
|
TwoWire ** |
ppWire |
|
) |
| |
|
inlinestaticprivate |
begin Invoked to begin an I2C connection, based on the specfied bus and offset.
- Note
- can be invoked multiple times if the I2C bus and/or offset changes.
- Parameters
-
| bus | is the I2C bus number (0 or 1) |
| address | is the offset from the base I2C address (passed in on the constuctor) |
| ppWire | is the TwoWire instance pointer to be published to the caller |
- Note
- I2C devices typically have DIP switches to enable setting the devices address offset value. If not available offset should = 0. This value must match the offset value for the specific device to connect too.
Definition at line 506 of file LccNodeI2c.h.
◆ _isConnected()
| static bool LccNodeI2c::_isConnected |
( |
const uint8_t |
bus, |
|
|
const uint8_t |
address, |
|
|
TwoWire * |
pWire = nullptr |
|
) |
| |
|
inlinestaticprivate |
Check if an I2C device at the given address responds.
- Parameters
-
| bus | The I2C bus number (0 or 1). |
| address | The 7-bit I2C device address. |
| pWire | Optional pointer to a TwoWire instance. If nullptr, the default bus will be used. |
- Returns
- True if the device acknowledges, false otherwise.
Definition at line 460 of file LccNodeI2c.h.
◆ _selectWire()
| static TwoWire * LccNodeI2c::_selectWire |
( |
uint8_t |
bus, |
|
|
TwoWire * |
pWire = nullptr |
|
) |
| |
|
inlinestaticprivate |
Selects the appropriate TwoWire instance for the given bus.
- If a non-null pointer is provided, it is returned directly.
- Otherwise, bus 0 returns &Wire and bus 1 returns &Wire1.
- Parameters
-
| bus | I²C bus index (0 or 1) |
| pWire | Optional pointer supplied by the caller |
- Returns
- Pointer to the chosen TwoWire instance
Definition at line 487 of file LccNodeI2c.h.
◆ begin() [1/3]
| bool LccNodeI2c::begin |
( |
const uint8_t |
bus, |
|
|
const uint8_t |
addressOffset |
|
) |
| |
|
inline |
begin Invoked to begin I2C connection, based on the specfied bus and offset.
- Note
- can be invoked multiple times if the I2C bus and/or offset changes.
- Parameters
-
| bus | is the I2C bus number (0 or 1) |
| addressOffset | is the I2C offset (0-7) set by PCB Dip switches, added to base I2C address (MCP23017 uses 0x20, passed in on the constuctor |
- Returns
- true if successful connection to device
- Note
- For LCC Fusion, I2C devices typically have DIP switches to enable setting the devices address offset value. If not available offset should = 0. This value must match the offset value for the specific device to connect too.
-
addressBase_ is assigned by the constructor, defaults to MCP's base address of x020
Definition at line 84 of file LccNodeI2c.h.
◆ begin() [2/3]
| bool LccNodeI2c::begin |
( |
const uint8_t |
bus, |
|
|
const uint8_t |
addressOffset, |
|
|
Adafruit_MCP23017 * |
pMcp |
|
) |
| |
|
inline |
begin Invoked to begin an MCP (over I2C) connection, based on the specfied bus and offset.
- Note
- can be invoked multiple times if the I2C bus and/or offset changes.
- Parameters
-
| bus | is the I2C bus number (0 or 1) |
| addressOffset | is the I2C offset (0-7) set by PCB Dip switches, added to base I2C address (MCP23017 uses 0x20, passed in on the constuctor |
| pMcp | is the Adafruit_MCP23017 object |
- Returns
- true if successful connection to device
- Note
- I2C/MCP devices typically have DIP switches to enable setting the devices address offset value. If not available offset should = 0. This value must match the offset value for the specific device to connect too.
Definition at line 103 of file LccNodeI2c.h.
◆ begin() [3/3]
| bool LccNodeI2c::begin |
( |
const uint8_t |
bus, |
|
|
const uint8_t |
addressOffset, |
|
|
FaBoPWM * |
pPwm |
|
) |
| |
|
inline |
begin Invoked to begin an PWM (over I2C) connection, based on the specfied bus and offset.
- Note
- can be invoked multiple times if the I2C bus and/or offset changes.
- Parameters
-
| bus | is the I2C bus number (0 or 1) |
| addressOffset | is the I2C offset (0-7) set by PCB Dip switches, added to base I2C address (PCA9685 uses 0x40, passed in on the constuctor |
| pPwm | is the FaBoPWM object |
- Returns
- true if successful connection to device
- Note
- I2C/PWM devices typically have DIP switches to enable setting the devices address offset value. If not available offset should = 0. This value must match the offset value for the specific device to connect too.
Definition at line 122 of file LccNodeI2c.h.
◆ get() [1/2]
| bool LccNodeI2c::get |
( |
char * |
message, |
|
|
const size_t |
messageLength |
|
) |
| |
|
inline |
receives character data from I2C enabled device, based the I2C bus and address previously configured.
- Parameters
-
| [in,out] | message | is updated with bytes received from the I2C slave using requestFrom(address, numBytes) |
| messageLength | is the size of the message buffer (or # bytes expected from slave, which is less than size of buffer) |
- Returns
- true if number of bytes received matches size of in/out message buffer
Definition at line 309 of file LccNodeI2c.h.
◆ get() [2/2]
template<typename T >
| bool LccNodeI2c::get |
( |
T & |
out | ) |
|
|
inline |
receives integer data from I2C enabled device, based the I2C bus and address previously configured.
- Parameters
-
| [in,out] | out | is an integer or char that is updated with bytes received from the I2C slave using requestFrom(address, numBytes) |
- Note
- data types include; char, all sizes of signed/unsigned integers, float, long, double, enum, and struct/classes
- Returns
- true if number of bytes received matches size of in/out message buffer
Definition at line 327 of file LccNodeI2c.h.
◆ polling()
| Polling * LccNodeI2c::polling |
( |
| ) |
|
|
inline |
- Returns
- the instance to give to the RefreshLoop object.
Definition at line 344 of file LccNodeI2c.h.
◆ send()
| bool LccNodeI2c::send |
( |
char * |
message | ) |
|
|
inline |
send invoked to send a 'message' to an I2C enabled device, based the I2C bus and address previously configured.
- Note
- assumes the message was delivered.
- Parameters
-
| message | is the text message to send |
- Note
- max data length is 32 bytes
Definition at line 293 of file LccNodeI2c.h.
The documentation for this class was generated from the following file: