NetBurner 3.1
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. More...
 
void setup (uint32_t busSpeed)
 Initialize the I2C module. More...
 
void resetBus ()
 Reset the I2C bus.
 
Result_t DoTransaction (I2CTxn_t *pTransaction, bool bRepeatedStart=false)
 Start an I2C transaction. More...
 
Result_t writeReg8 (uint8_t devAddr, uint8_t reg, uint8_t dat)
 Write an 8-bit value to a I2C slave device register. More...
 
Result_t readReg8 (uint8_t devAddr, uint8_t reg, uint8_t &dat)
 Read an 8-bit value form an I2C slave device register. More...
 
Result_t writeRegN (uint8_t devAddr, uint8_t reg, uint8_t *buf, uint32_t blen)
 Write a number of 8-bit values to an I2C slave to the specified register address. More...
 
Result_t readRegN (uint8_t devAddr, uint8_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...
 

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,
uint8_t  reg,
uint8_t &  dat 
)

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

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

◆ readRegN()

Result_t I2C::readRegN ( uint8_t  devAddr,
uint8_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 to read
*bufPointer to buffer to store received data
blenNumber of bytes to read
Returns
Result_t

◆ setup()

void I2C::setup ( uint32_t  busSpeed)

Initialize the I2C module.

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

◆ writeReg8()

Result_t I2C::writeReg8 ( uint8_t  devAddr,
uint8_t  reg,
uint8_t  dat 
)

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

Parameters
devAddrAddress of I2C device
regRegister to write
datData to write to register
Returns
Result_t

◆ writeRegN()

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