SpaIot Library
TwoWireSlave

#include <twowireslave.h>

Public Member Functions

 TwoWireSlave (uint8_t slaveAddress, TwoWire &bus=Wire)
 Constructor. More...
 
int write (uint8_t value)
 Write a byte in the integrated circuit. More...
 
int read ()
 Reading a byte in the integrated circuit. More...
 
int write (const uint8_t *values, uint16_t len)
 Write several bytes in the integrated circuit. More...
 
int read (uint8_t *values, uint16_t len)
 Reading several bytes in the integrated circuit. More...
 
int write (uint8_t dataAddress, uint8_t value)
 Write a byte in an integrated circuit register. More...
 
int read (uint8_t dataAddress)
 Reading a byte in an integrated circuit register. More...
 
int write (uint8_t dataAddress, const uint8_t *values, uint16_t len)
 Write bytes in integrated circuit registers. More...
 
int read (uint8_t dataAddress, uint8_t *values, uint16_t len)
 Reading several bytes in the integrated circuit. More...
 
uint8_t address () const
 Reading of the slave m_address of the integrated circuit. More...
 
void setAddress (uint8_t slaveAddress)
 Change of the slave m_address of the integrated circuit. More...
 
TwoWire & bus () const
 Returns the I²C bus used to access the integrated circuit. More...
 

Detailed Description

Allows write-read access to an I²C slave circuit

Constructor & Destructor Documentation

◆ TwoWireSlave()

TwoWireSlave::TwoWireSlave ( uint8_t  slaveAddress,
TwoWire &  bus = Wire 
)

Constructor.

Parameters
slaveAddress7-bit I²C slave m_address, right-aligned
busreference on the I²C bus to use

Member Function Documentation

◆ address()

uint8_t TwoWireSlave::address ( ) const
inline

Reading of the slave m_address of the integrated circuit.

Returns
7-bit I²C slave m_address, right-aligned

◆ bus()

TwoWire & TwoWireSlave::bus ( ) const
inline

Returns the I²C bus used to access the integrated circuit.

Returns
reference on the I²C bus used

◆ read() [1/4]

int TwoWireSlave::read ( )

Reading a byte in the integrated circuit.

The frame is made up of a start condition, the slave m_address with an RW bit high, the byte read and a stop condition.

Returns
byte read as unsigned, -1 if error

◆ read() [2/4]

int TwoWireSlave::read ( uint8_t *  values,
uint16_t  len 
)

Reading several bytes in the integrated circuit.

The frame is made up of a start condition, the slave m_address with an RW bit high, the bytes read and a stop condition.

Parameters
valuespointer where to store bytes, must be able to store at least n bytes
lennumber of bytes to read
Returns
number of bytes read, -1 if error

◆ read() [3/4]

int TwoWireSlave::read ( uint8_t  dataAddress)

Reading a byte in an integrated circuit register.

The frame is made up of a start condition, the slave m_address with an RW bit high, the dataAddress, the byte read and a stop condition.

Parameters
dataAddressregister m_address or control byte
Returns
byte read

◆ read() [4/4]

int TwoWireSlave::read ( uint8_t  dataAddress,
uint8_t *  values,
uint16_t  len 
)

Reading several bytes in the integrated circuit.

The frame is made up of a start condition, the slave m_address with an RW bit high, the dataAddress, the bytes read and a stop condition.

Parameters
dataAddressregister m_address or control byte
valuespointer where to store bytes, must be able to store at least n bytes
lennumber of bytes to read
Returns
number of bytes read, -1 if error

◆ setAddress()

void TwoWireSlave::setAddress ( uint8_t  slaveAddress)
inline

Change of the slave m_address of the integrated circuit.

Parameters
slaveAddress7-bit I²C slave m_address, right-aligned

◆ write() [1/4]

int TwoWireSlave::write ( const uint8_t *  values,
uint16_t  len 
)

Write several bytes in the integrated circuit.

The frame is made up of a start condition, the slave m_address with an RW bit low, the bytes to write and a stop condition.

Parameters
valuespointer to the bytes to write
lennumber of bytes to write
Returns
number of bytes written, -1 if error

◆ write() [2/4]

int TwoWireSlave::write ( uint8_t  dataAddress,
const uint8_t *  values,
uint16_t  len 
)

Write bytes in integrated circuit registers.

The frame is made up of a start condition, the slave m_address with an RW bit low, the dataAddress, the bytes to write and a stop condition.

Parameters
dataAddressregister m_address or control byte
valuespointer to the bytes to write
lennumber of bytes to write
Returns
number of bytes written, -1 if error

◆ write() [3/4]

int TwoWireSlave::write ( uint8_t  dataAddress,
uint8_t  value 
)

Write a byte in an integrated circuit register.

The frame is made up of a start condition, the slave m_address with an RW bit low, the dataAddress, the value byte and a stop condition.

Parameters
dataAddressregister m_address or control byte
valuebyte to write
Returns
number of bytes written, -1 if error

◆ write() [4/4]

int TwoWireSlave::write ( uint8_t  value)

Write a byte in the integrated circuit.

The frame is made up of a start condition, the slave m_address with an RW bit low, the value byte and a stop condition.

Parameters
valuebyte to write
Returns
number of bytes written, -1 if error