NetBurner 3.3.9
PDF Version
I2CDevice Class Reference

I2C Device Class (recommended) More...

#include <i2c.h>

Public Member Functions

 I2CDevice (I2C &pInterface, uint8_t deviceAddress, uint8_t numAddressBytes=1)
 Initialize the I2C module. More...
 
uint8_t getI2CAddress ()
 Get device's I2C address. More...
 
void setup (uint32_t busSpeed)
 Setup the I2C peripheral module. More...
 
void resetBus ()
 Reset the I2C bus.
 
I2C::Result_t writeReg8 (uint32_t reg, uint8_t data)
 Write an 8-bit value to an I2C slave device register. More...
 
I2C::Result_t readReg8 (uint32_t reg, uint8_t &data)
 Read an 8-bit value form an I2C slave device register. More...
 
I2C::Result_t writeRegN (uint32_t reg, const uint8_t *buf, uint32_t blen)
 Write a number of 8-bit values to an I2C slave to the specified register address. More...
 
I2C::Result_t readRegN (uint32_t reg, uint8_t *buf, uint32_t blen)
 Read a number of 8-bit values from an I2C slave at the specified register address. More...
 

Detailed Description

I2C Device Class (recommended)

For I2C communication, you can choose the I2CDevice class, the I2C class, or the WireIntf class. The recommended interface is the I2CDevice class.

For example, to create an object for an analog to digital converter:

I2CDevice AdcDevice(i2c[I2C_MODULE_NUM], I2C_ADC_ADDRESS);
I2C Device Class (recommended)
Definition: i2c.h:438

To read a 16 bit value:

uint8_t I2CStat = AdcDevice.readRegN(0x00, buf, 2);

Constructor & Destructor Documentation

◆ I2CDevice()

I2CDevice::I2CDevice ( I2C pInterface,
uint8_t  deviceAddress,
uint8_t  numAddressBytes = 1 
)
inline

Initialize the I2C module.

Parameters
pInterfacePointer to the I2C interface to use. This will normally be one of the preallocated I2C modules in the i2c[] array: i2c[0] (default), i2c[1] or i2c[2].
deviceAddressI2C device address
numAddressBytesNumber of address bytes to send to specify the register or address to access for a read or write operation. Refer to your I2C device data sheet to determine the correct number. The I2C address range is 24-bits maximum (3 bytes). The default value is 1 byte, representing an address range of 0 to 255.

Member Function Documentation

◆ getI2CAddress()

uint8_t I2CDevice::getI2CAddress ( )
inline

Get device's I2C address.

Note that the return address will be just the I2C address bits, not including the read/write bit. If your device data sheet specifies the address byte to include the read/write bit, that value would be this address left shifted by 1. For example, if a device data sheet specifies the address as 0xA2 and includes the read/write bit, the actual address would be 0x51.

Returns
The device's I2C address

◆ readReg8()

I2C::Result_t I2CDevice::readReg8 ( uint32_t  reg,
uint8_t &  data 
)
inline

Read an 8-bit value form an I2C slave device register.

Parameters
regRegister address to read
dataReference to variable in which to store the register data
Returns
I2C::Result_t

◆ readRegN()

I2C::Result_t I2CDevice::readRegN ( uint32_t  reg,
uint8_t *  buf,
uint32_t  blen 
)
inline

Read a number of 8-bit values from an I2C slave at the specified register address.

Parameters
regRegister address to read
*bufPointer to buffer to store received data
blenNumber of bytes to read
Returns
I2C::Result_t

◆ setup()

void I2CDevice::setup ( uint32_t  busSpeed)
inline

Setup the I2C peripheral module.

Parameters
busSpeedTarget bus speed. It the specified speed cannot be achieved, a lower bus speed may be enabled.

◆ writeReg8()

I2C::Result_t I2CDevice::writeReg8 ( uint32_t  reg,
uint8_t  data 
)
inline

Write an 8-bit value to an I2C slave device register.

Parameters
regRegister address to write
dataData to write to register
Returns
I2C::Result_t

◆ writeRegN()

I2C::Result_t I2CDevice::writeRegN ( uint32_t  reg,
const uint8_t *  buf,
uint32_t  blen 
)
inline

Write a number of 8-bit values to an I2C slave to the specified register address.

Executing this function will send the following: a start bit, the slave 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
regRegister address to write
*bufPointer to buffer containing data to write
blenNumber of bytes to write
Returns
I2C::Result_t

The documentation for this class was generated from the following file: