|
| | BBI2C (PinIO scl, PinIO sda) |
| | Construct a software I2C bus on the specified GPIO pins.
|
| | BBI2C (const BBI2C &rhs) |
| | Copy constructor.
|
| void | setup (uint32_t maxBusSpeed) |
| | Configure the pins and prepare the software I2C bus for use.
|
|
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 | writeReg16 (uint8_t devAddr, uint32_t reg, uint16_t data, int byteOrder) |
| | Write a 16-bit value to an I2C device register.
|
| virtual Result_t | writeReg32 (uint8_t devAddr, uint32_t reg, uint32_t data, int byteOrder) |
| | Write a 32-bit value to an I2C 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.
|
| uint32_t | GetBusSpeed () |
| | Return the bus speed the software timing is currently set to.
|
Software (bit-banged) I2C master driver.
BBI2C implements an I2C master in software by toggling two GPIO pins. It does not use the I2C peripheral hardware. Use it when a design needs an I2C bus on pins that are not routed to a hardware I2C module, or when all hardware modules are already in use.
For hardware I2C, use the TwoWire class in Wire.h, which drives the I2C peripheral modules and provides an Arduino-compatible API.
BBI2C provides register-level convenience calls (readRegN(), writeRegN() and the fixed-width variants) and supports device register addresses of 0 to 3 bytes via setNumAddressBytes(), for parts with no register pointer, or with 8-, 16- or 24-bit register addressing.
Objects are constructed with the SCL and SDA pins to use; nothing is instantiated automatically. Call setup() before the first transaction.
| uint32_t BBI2C::GetBusSpeed |
( |
| ) |
|
Return the bus speed the software timing is currently set to.
Reports the nominal speed implied by the clock delay set up by the last setup() call, which may be lower than the speed requested because the delay is a whole number of timer counts.
This is the timing the driver aims for, not measured throughput. The rate actually seen on the bus is lower, because the time spent toggling the GPIO pins between delays is not accounted for here.
- Return values
-
| Bus | speed in Hz, or 0 if the requested speed was high enough that no software delay is inserted, in which case the bus runs as fast as the GPIO pins can be toggled. |
| 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. |