Convenience wrapper binding a TwoWire instance and device address.
More...
#include <Wire.h>
|
| | TwoWireObject (TwoWire &w, uint8_t addr) |
| | Construct a TwoWireObject with a specific TwoWire instance.
|
| |
| | TwoWireObject (uint8_t addr) |
| | Construct a TwoWireObject using the global Wire instance.
|
| |
|
void | reset () |
| | Reset the I2C system and unhang the bus.
|
| |
| bool | ping () |
| | Check to see if the bound device address exists on this bus.
|
| |
| int | writeRegN (uint32_t reg, const uint8_t *buf, uint32_t blen) |
| | Write a number of 8-bit values to the specified register address.
|
| |
| int | readRegN (uint32_t reg, uint8_t *buf, uint32_t blen) |
| | Read a number of 8-bit values from the specified register address.
|
| |
| int | writeReg8 (uint32_t reg, uint8_t data) |
| | Write an 8-bit value to a target device register.
|
| |
| int | readReg8 (uint32_t reg, uint8_t &data) |
| | Read an 8-bit value from a target device register.
|
| |
Convenience wrapper binding a TwoWire instance and device address.
TwoWireObject stores a reference to a TwoWire instance and a fixed 7-bit I2C device address, providing a cleaner API for register-based access to a single device. All methods delegate to the underlying TwoWire, automatically supplying the stored device address.
Expand for Example Usage
TwoWireObject Example
- Example: Using TwoWireObject for Register Access
#include <wire.h>
void UserMain(void *pd)
{
if (Sensor.ping())
{
uint8_t id;
Sensor.readReg8(0x75, id);
iprintf("Device ID: 0x%02X\r\n", id);
Sensor.writeReg8(0x6B, 0x00);
}
}
Arduino Wire-compatible I2C controller/target interface.
Definition Wire.h:255
void begin(uint8_t slave_addr=0)
Initialize the I2C interface.
Convenience wrapper binding a TwoWire instance and device address.
Definition Wire.h:839
class TwoWire Wire
Pre-declared global TwoWire instance using platform default pins.
Definition I2C/Wire/PAC193X/src/main.cpp:15
- See also
- TwoWire
◆ TwoWireObject() [1/2]
| TwoWireObject::TwoWireObject |
( |
TwoWire & | w, |
|
|
uint8_t | addr ) |
|
inline |
Construct a TwoWireObject with a specific TwoWire instance.
- Parameters
-
| w | Reference to the TwoWire instance to use |
| addr | 7-bit I2C device address |
◆ TwoWireObject() [2/2]
| TwoWireObject::TwoWireObject |
( |
uint8_t | addr | ) |
|
|
inline |
Construct a TwoWireObject using the global Wire instance.
- Parameters
-
| addr | 7-bit I2C device address |
◆ ping()
| bool TwoWireObject::ping |
( |
| ) |
|
|
inline |
Check to see if the bound device address exists on this bus.
- Return values
-
| true | if the address exists |
◆ readReg8()
| int TwoWireObject::readReg8 |
( |
uint32_t | reg, |
|
|
uint8_t & | data ) |
|
inline |
Read an 8-bit value from a target device register.
- Parameters
-
| reg | Register address to read |
| data | Reference to variable in which to store the register data |
- Returns
- Wire Result Codes
◆ readRegN()
| int TwoWireObject::readRegN |
( |
uint32_t | reg, |
|
|
uint8_t * | buf, |
|
|
uint32_t | blen ) |
|
inline |
Read a number of 8-bit values from the specified register address.
- Parameters
-
| reg | Register address to read |
| *buf | Pointer to buffer to store received data |
| blen | Number of bytes to read |
- Returns
- Wire Result Codes
◆ writeReg8()
| int TwoWireObject::writeReg8 |
( |
uint32_t | reg, |
|
|
uint8_t | data ) |
|
inline |
Write an 8-bit value to a target device register.
- Parameters
-
| reg | Register address to write |
| data | Data to write to register |
- Returns
- Wire Result Codes
◆ writeRegN()
| int TwoWireObject::writeRegN |
( |
uint32_t | reg, |
|
|
const uint8_t * | buf, |
|
|
uint32_t | blen ) |
|
inline |
Write a number of 8-bit values to the specified register address.
Executing this function will send the following: a start bit, the target device address and read/write bit, the 8-bit data bytes, and finally a stop bit. Note that the address is not incremented with each 8-bit data value.
- Parameters
-
| reg | Register address to write |
| *buf | Pointer to buffer containing data to write |
| blen | Number of bytes to write |
- Returns
- Wire Result Codes
The documentation for this class was generated from the following file: