NetBurner 3.5.0
PDF Version
 
I2C Class Reference

I2C Peripheral Class. More...

#include <i2c.h>

Public Types

enum  Result_t {
  I2C_RES_ACK , I2C_RES_NACK , I2C_RES_ARB_LST , I2C_RES_BUSY ,
  I2C_RES_ARG
}
 Return result types. More...
 

Public Member Functions

 I2C (int module)
 Constructor for the I2C peripheral module.
 
void setup (uint32_t busSpeed)
 Setup the I2C peripheral interface.
 
void resetBus ()
 Reset the I2C bus.
 
Result_t DoTransaction (I2CTxn_t *pTransaction, bool bRepeatedStart=false)
 Start an I2C transaction.
 
void setNumAddressBytes (uint8_t numAddressBytes=1)
 Specify the register address size for a read or write transaction. A number of bytes, from 0 to 3, can be sent to specify an address up to 24-bit (3 bytes): 0 = none, 1 = 8-bits, 2 = 16-bits, 3 = 24-bits.
 
Result_t writeReg8 (uint8_t devAddr, uint32_t reg, uint8_t data)
 Write an 8-bit value to a I2C slave device register.
 
Result_t readReg8 (uint8_t devAddr, uint32_t reg, uint8_t &data)
 Read an 8-bit value form an I2C slave device register.
 
Result_t writeRegN (uint8_t devAddr, 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.
 
Result_t readRegN (uint8_t devAddr, 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.
 

Friends

class WireIntf
 

Detailed Description

I2C Peripheral Class.

For I2C communication, you can choose the WireIntf class, or the I2C class. The WireIntf class is simpler to use, while the I2C class provides more low level control.

Note that the system automatically instantiates I2C and WireIntf objects for each of the I2C peripheral modules. The WireIntf objects can be accessed with: Wire, Wire1 and Wire2. The I2C objects can be accesses with I2C[0], I2C[1] and I2C[2].

Member Enumeration Documentation

◆ Result_t

Return result types.

Enumerator
I2C_RES_ACK 

Acknowledged.

I2C_RES_NACK 

Not acknowledged.

I2C_RES_ARB_LST 

Arbitration listening.

I2C_RES_BUSY 

Bus is busy.

I2C_RES_ARG 

Bad argument.

Constructor & Destructor Documentation

◆ I2C()

I2C::I2C ( int module)

Constructor for the I2C peripheral module.

Parameters
moduleThe I2C module to instantiate (0, 1 or 2)

Member Function Documentation

◆ DoTransaction()

Result_t I2C::DoTransaction ( I2CTxn_t * pTransaction,
bool bRepeatedStart = false )

Start an I2C transaction.

Execute the transaction pointed to by pTransaction

Parameters
*pTransactionPointer to the transaction to execute
bRepeatedStartRepeat the I2C start sequence
Returns
Result_t

◆ readReg8()

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

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

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

◆ readRegN()

Result_t I2C::readRegN ( uint8_t devAddr,
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.

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

◆ setNumAddressBytes()

void I2C::setNumAddressBytes ( uint8_t numAddressBytes = 1)
inline

Specify the register address size for a read or write transaction. A number of bytes, from 0 to 3, can be sent to specify an address up to 24-bit (3 bytes): 0 = none, 1 = 8-bits, 2 = 16-bits, 3 = 24-bits.

If you are using a single I2C device, or all devices use the same address size, this function only needs to be called once. If you have multiple I2C devices with different address/register bit sizes, then this function should be called before each read/write operation for each different device.

Parameters
numAddressBytesThe number of address bytes to send: 0 - 3. The default value is 1 byte.

◆ setup()

void I2C::setup ( uint32_t busSpeed)

Setup the I2C peripheral interface.

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

◆ writeReg8()

Result_t I2C::writeReg8 ( uint8_t devAddr,
uint32_t reg,
uint8_t data )

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

Parameters
devAddrAddress of I2C device
regRegister address to write
dataData to write to register
Returns
Result_t

◆ writeRegN()

Result_t I2C::writeRegN ( uint8_t devAddr,
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.

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
devAddrAddress of I2C device
regRegister address to write
*bufPointer to buffer containing data to write
blenNumber of bytes to write
Returns
Result_t

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