I2Cdevlib

I2C device library collection for AVR/Arduino or other C++-based MCUs

Public Member Functions | Static Public Member Functions | Static Public Attributes
I2Cdev Class Reference

Public Member Functions

 I2Cdev ()

Static Public Member Functions

static int8_t readBit (uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout)
static int8_t readBitW (uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout)
static int8_t readBits (uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout)
static int8_t readBitsW (uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout)
static int8_t readByte (uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout)
static int8_t readWord (uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout)
static int8_t readBytes (uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout)
static int8_t readWords (uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout)
static bool writeBit (uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data)
static bool writeBitW (uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data)
static bool writeBits (uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data)
static bool writeBitsW (uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data)
static bool writeByte (uint8_t devAddr, uint8_t regAddr, uint8_t data)
static bool writeWord (uint8_t devAddr, uint8_t regAddr, uint16_t data)
static bool writeBytes (uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data)
static bool writeWords (uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data)

Static Public Attributes

static uint16_t readTimeout = I2CDEV_DEFAULT_READ_TIMEOUT

Constructor & Destructor Documentation

I2Cdev::I2Cdev ( )

Default constructor.


Member Function Documentation

int8_t I2Cdev::readBit ( uint8_t  devAddr,
uint8_t  regAddr,
uint8_t  bitNum,
uint8_t *  data,
uint16_t  timeout = I2Cdev::readTimeout 
) [static]

Read a single bit from an 8-bit device register.

Parameters:
devAddrI2C slave device address
regAddrRegister regAddr to read from
bitNumBit position to read (0-7)
dataContainer for single bit value
timeoutOptional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout)
Returns:
Status of read operation (true = success)
int8_t I2Cdev::readBits ( uint8_t  devAddr,
uint8_t  regAddr,
uint8_t  bitStart,
uint8_t  length,
uint8_t *  data,
uint16_t  timeout = I2Cdev::readTimeout 
) [static]

Read multiple bits from an 8-bit device register.

Parameters:
devAddrI2C slave device address
regAddrRegister regAddr to read from
bitStartFirst bit position to read (0-7)
lengthNumber of bits to read (not more than 8)
dataContainer for right-aligned value (i.e. '101' read from any bitStart position will equal 0x05)
timeoutOptional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout)
Returns:
Status of read operation (true = success)
int8_t I2Cdev::readBitsW ( uint8_t  devAddr,
uint8_t  regAddr,
uint8_t  bitStart,
uint8_t  length,
uint16_t *  data,
uint16_t  timeout = I2Cdev::readTimeout 
) [static]

Read multiple bits from a 16-bit device register.

Parameters:
devAddrI2C slave device address
regAddrRegister regAddr to read from
bitStartFirst bit position to read (0-15)
lengthNumber of bits to read (not more than 16)
dataContainer for right-aligned value (i.e. '101' read from any bitStart position will equal 0x05)
timeoutOptional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout)
Returns:
Status of read operation (1 = success, 0 = failure, -1 = timeout)
int8_t I2Cdev::readBitW ( uint8_t  devAddr,
uint8_t  regAddr,
uint8_t  bitNum,
uint16_t *  data,
uint16_t  timeout = I2Cdev::readTimeout 
) [static]

Read a single bit from a 16-bit device register.

Parameters:
devAddrI2C slave device address
regAddrRegister regAddr to read from
bitNumBit position to read (0-15)
dataContainer for single bit value
timeoutOptional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout)
Returns:
Status of read operation (true = success)
int8_t I2Cdev::readByte ( uint8_t  devAddr,
uint8_t  regAddr,
uint8_t *  data,
uint16_t  timeout = I2Cdev::readTimeout 
) [static]

Read single byte from an 8-bit device register.

Parameters:
devAddrI2C slave device address
regAddrRegister regAddr to read from
dataContainer for byte value read from device
timeoutOptional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout)
Returns:
Status of read operation (true = success)
int8_t I2Cdev::readBytes ( uint8_t  devAddr,
uint8_t  regAddr,
uint8_t  length,
uint8_t *  data,
uint16_t  timeout = I2Cdev::readTimeout 
) [static]

Read multiple bytes from an 8-bit device register.

Parameters:
devAddrI2C slave device address
regAddrFirst register regAddr to read from
lengthNumber of bytes to read
dataBuffer to store read data in
timeoutOptional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout)
Returns:
Number of bytes read (0 indicates failure)
int8_t I2Cdev::readWord ( uint8_t  devAddr,
uint8_t  regAddr,
uint16_t *  data,
uint16_t  timeout = I2Cdev::readTimeout 
) [static]

Read single word from a 16-bit device register.

Parameters:
devAddrI2C slave device address
regAddrRegister regAddr to read from
dataContainer for word value read from device
timeoutOptional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout)
Returns:
Status of read operation (true = success)
int8_t I2Cdev::readWords ( uint8_t  devAddr,
uint8_t  regAddr,
uint8_t  length,
uint16_t *  data,
uint16_t  timeout = I2Cdev::readTimeout 
) [static]

Read multiple words from a 16-bit device register.

Parameters:
devAddrI2C slave device address
regAddrFirst register regAddr to read from
lengthNumber of words to read
dataBuffer to store read data in
timeoutOptional read timeout in milliseconds (0 to disable, leave off to use default class value in I2Cdev::readTimeout)
Returns:
Number of words read (0 indicates failure)
bool I2Cdev::writeBit ( uint8_t  devAddr,
uint8_t  regAddr,
uint8_t  bitNum,
uint8_t  data 
) [static]

write a single bit in an 8-bit device register.

Parameters:
devAddrI2C slave device address
regAddrRegister regAddr to write to
bitNumBit position to write (0-7)
valueNew bit value to write
Returns:
Status of operation (true = success)
bool I2Cdev::writeBits ( uint8_t  devAddr,
uint8_t  regAddr,
uint8_t  bitStart,
uint8_t  length,
uint8_t  data 
) [static]

Write multiple bits in an 8-bit device register.

Parameters:
devAddrI2C slave device address
regAddrRegister regAddr to write to
bitStartFirst bit position to write (0-7)
lengthNumber of bits to write (not more than 8)
dataRight-aligned value to write
Returns:
Status of operation (true = success)
bool I2Cdev::writeBitsW ( uint8_t  devAddr,
uint8_t  regAddr,
uint8_t  bitStart,
uint8_t  length,
uint16_t  data 
) [static]

Write multiple bits in a 16-bit device register.

Parameters:
devAddrI2C slave device address
regAddrRegister regAddr to write to
bitStartFirst bit position to write (0-15)
lengthNumber of bits to write (not more than 16)
dataRight-aligned value to write
Returns:
Status of operation (true = success)
bool I2Cdev::writeBitW ( uint8_t  devAddr,
uint8_t  regAddr,
uint8_t  bitNum,
uint16_t  data 
) [static]

write a single bit in a 16-bit device register.

Parameters:
devAddrI2C slave device address
regAddrRegister regAddr to write to
bitNumBit position to write (0-15)
valueNew bit value to write
Returns:
Status of operation (true = success)
bool I2Cdev::writeByte ( uint8_t  devAddr,
uint8_t  regAddr,
uint8_t  data 
) [static]

Write single byte to an 8-bit device register.

Parameters:
devAddrI2C slave device address
regAddrRegister address to write to
dataNew byte value to write
Returns:
Status of operation (true = success)
bool I2Cdev::writeBytes ( uint8_t  devAddr,
uint8_t  regAddr,
uint8_t  length,
uint8_t *  data 
) [static]

Write multiple bytes to an 8-bit device register.

Parameters:
devAddrI2C slave device address
regAddrFirst register address to write to
lengthNumber of bytes to write
dataBuffer to copy new data from
Returns:
Status of operation (true = success)
bool I2Cdev::writeWord ( uint8_t  devAddr,
uint8_t  regAddr,
uint16_t  data 
) [static]

Write single word to a 16-bit device register.

Parameters:
devAddrI2C slave device address
regAddrRegister address to write to
dataNew word value to write
Returns:
Status of operation (true = success)
bool I2Cdev::writeWords ( uint8_t  devAddr,
uint8_t  regAddr,
uint8_t  length,
uint16_t *  data 
) [static]

Write multiple words to a 16-bit device register.

Parameters:
devAddrI2C slave device address
regAddrFirst register address to write to
lengthNumber of words to write
dataBuffer to copy new data from
Returns:
Status of operation (true = success)

Field Documentation

uint16_t I2Cdev::readTimeout = I2CDEV_DEFAULT_READ_TIMEOUT [static]

Default timeout value for read operations. Set this to 0 to disable timeout detection.


The documentation for this class was generated from the following files:
 All Data Structures Functions Variables