I2C Peripheral Class.
More...
#include <bb_i2c.h>
|
| BBI2C (PinIO scl, PinIO sda) |
| Constructor for the I2C peripheral module.
|
|
void | setup (uint32_t maxBusSpeed) |
| Setup the I2C peripheral interface.
|
|
void | resetBus () |
| Reset the I2C bus.
|
|
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.
|
|
virtual Result_t | writeReg8 (uint8_t devAddr, uint32_t reg, uint8_t data) |
| Write an 8-bit value to a I2C slave device register.
|
|
virtual Result_t | readReg8 (uint8_t devAddr, uint32_t reg, uint8_t &data) |
| Read an 8-bit value form an I2C slave device register.
|
|
virtual Result_t | writeRegN (uint8_t devAddr, uint32_t reg, uint8_t *buf, uint32_t blen) |
| Write a number of 8-bit values to an I2C slave to the specified register address.
|
|
virtual 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.
|
|
void | SetMaxBusDelay (uint16_t milliseconds) |
| Set the maximum duration that the bus is allowed to be in use without being clocked before being forcibly reset.
|
|
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].
◆ Result_t
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.
|
I2C_RES_IN_PROGRESS | Another transaction is currently in progress.
|
I2C_RES_ERR | Unknown Error.
|
◆ BBI2C()
Constructor for the I2C peripheral module.
- Parameters
-
◆ readReg8()
virtual Result_t BBI2C::readReg8 |
( |
uint8_t | devAddr, |
|
|
uint32_t | reg, |
|
|
uint8_t & | data ) |
|
virtual |
Read an 8-bit value form an I2C slave device register.
- Parameters
-
devAddr | Address of I2C device |
reg | Register address to read |
data | Reference to variable in which to store the register data |
- Returns
- Result_t
◆ readRegN()
virtual Result_t BBI2C::readRegN |
( |
uint8_t | devAddr, |
|
|
uint32_t | reg, |
|
|
uint8_t * | buf, |
|
|
uint32_t | blen ) |
|
virtual |
Read a number of 8-bit values from an I2C slave at the specified register address.
- Parameters
-
devAddr | Address of I2C device |
reg | Register address to read |
*buf | Pointer to buffer to store received data |
blen | Number of bytes to read |
- Returns
- Result_t
◆ SetMaxBusDelay()
void BBI2C::SetMaxBusDelay |
( |
uint16_t | milliseconds | ) |
|
Set the maximum duration that the bus is allowed to be in use without being clocked before being forcibly reset.
- Parameters
-
milliseconds | Maximum number of milliseconds before triggering a bus reset |
◆ setNumAddressBytes()
void BBI2C::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
-
numAddressBytes | The number of address bytes to send: 0 - 3. The default value is 1 byte. |
◆ setup()
void BBI2C::setup |
( |
uint32_t | maxBusSpeed | ) |
|
Setup the I2C peripheral interface.
- Parameters
-
maxBusSpeed | Target bus speed. It the specified speed cannot be achieved, a lower bus speed may be enabled. |
◆ writeReg8()
virtual Result_t BBI2C::writeReg8 |
( |
uint8_t | devAddr, |
|
|
uint32_t | reg, |
|
|
uint8_t | data ) |
|
virtual |
Write an 8-bit value to a I2C slave device register.
- Parameters
-
devAddr | Address of I2C device |
reg | Register address to write |
data | Data to write to register |
- Returns
- Result_t
◆ writeRegN()
virtual Result_t BBI2C::writeRegN |
( |
uint8_t | devAddr, |
|
|
uint32_t | reg, |
|
|
uint8_t * | buf, |
|
|
uint32_t | blen ) |
|
virtual |
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
-
devAddr | Address of I2C device |
reg | Register address to write |
*buf | Pointer to buffer containing data to write |
blen | Number of bytes to write |
- Returns
- Result_t
The documentation for this class was generated from the following file: