Interface to I2C functions.
More...
#include <I2C.h>
|
| I2C () |
| Create an instance of an I2C object. More...
|
|
void | beginTransaction () |
| Begin a new I2C transaction. More...
|
|
void | endTransaction () |
| End an I2C transaction. More...
|
|
uint8_t | getAddress () const |
| Get the address of the I2C slave against which we are working. More...
|
|
void | init (uint8_t address, gpio_num_t sdaPin=DEFAULT_SDA_PIN, gpio_num_t sclPin=DEFAULT_CLK_PIN, uint32_t clkSpeed=DEFAULT_CLK_SPEED, i2c_port_t portNum=I2C_NUM_0, bool pullup=true) |
| Initialize the I2C interface. More...
|
|
void | read (uint8_t *bytes, size_t length, bool ack=true) |
| Read a sequence of bytes from the slave. More...
|
|
void | read (uint8_t *byte, bool ack=true) |
| Read a single byte from the slave. More...
|
|
void | scan () |
| Scan the I2C bus looking for devices. More...
|
|
void | setAddress (uint8_t address) |
| Set the address of the I2C slave against which we will be working. More...
|
|
void | setDebug (bool enabled) |
| enable or disable debugging. More...
|
|
bool | slavePresent (uint8_t address) |
| Determine if the slave is present and responding. More...
|
|
void | start () |
| Add an I2C start request to the command stream. More...
|
|
void | stop () |
| Add an I2C stop request to the command stream. More...
|
|
void | write (uint8_t byte, bool ack=true) |
| Write a single byte to the I2C slave. More...
|
|
void | write (uint8_t *bytes, size_t length, bool ack=true) |
| Write a sequence of byte to the I2C slave. More...
|
|
Interface to I2C functions.
Create an instance of an I2C object.
- Returns
- N/A.
void I2C::beginTransaction |
( |
| ) |
|
Begin a new I2C transaction.
Begin a transaction by adding an I2C start to the queue.
- Returns
- N/A.
void I2C::endTransaction |
( |
| ) |
|
End an I2C transaction.
This call will execute the I2C requests that have been queued up since the preceding call to the beginTransaction() function. An I2C stop() is also called.
- Returns
- N/A.
uint8_t I2C::getAddress |
( |
| ) |
const |
Get the address of the I2C slave against which we are working.
- Returns
- The address of the I2C slave.
Initialize the I2C interface.
- Parameters
-
[in] | address | The address of the slave device. |
[in] | sdaPin | The pin to use for SDA data. |
[in] | sclPin | The pin to use for SCL clock. |
- Returns
- N/A.
void I2C::read |
( |
uint8_t * |
bytes, |
|
|
size_t |
length, |
|
|
bool |
ack = true |
|
) |
| |
Read a sequence of bytes from the slave.
- Parameters
-
[out] | bytes | The address into which the read bytes will be stored. |
[in] | length | The number of expected bytes to read. |
[in] | ack | Whether or not we should send an ACK to the slave after reading a byte. |
- Returns
- N/A.
void I2C::read |
( |
uint8_t * |
byte, |
|
|
bool |
ack = true |
|
) |
| |
Read a single byte from the slave.
- Parameters
-
[out] | byte | The address into which the read byte will be stored. |
[in] | ack | Whether or not we should send an ACK to the slave after reading a byte. |
- Returns
- N/A.
Scan the I2C bus looking for devices.
A scan is performed on the I2C bus looking for devices. A table is written to the serial output describing what devices (if any) were found.
- Returns
- N/A.
void I2C::setAddress |
( |
uint8_t |
address | ) |
|
Set the address of the I2C slave against which we will be working.
- Parameters
-
[in] | address | The address of the I2C slave. |
void I2C::setDebug |
( |
bool |
enabled | ) |
|
enable or disable debugging.
- Parameters
-
[in] | enabled | Should debugging be enabled or disabled. |
- Returns
- N/A.
bool I2C::slavePresent |
( |
uint8_t |
address | ) |
|
Determine if the slave is present and responding.
- Parameters
-
[in] | The | address of the slave. |
- Returns
- True if the slave is present and false otherwise.
Add an I2C start request to the command stream.
- Returns
- N/A.
Add an I2C stop request to the command stream.
- Returns
- N/A.
void I2C::write |
( |
uint8_t |
byte, |
|
|
bool |
ack = true |
|
) |
| |
Write a single byte to the I2C slave.
- Parameters
-
[in] | byte | The byte to write to the slave. |
[in] | ack | Whether or not an acknowledgment is expected from the slave. |
- Returns
- N/A.
void I2C::write |
( |
uint8_t * |
bytes, |
|
|
size_t |
length, |
|
|
bool |
ack = true |
|
) |
| |
Write a sequence of byte to the I2C slave.
- Parameters
-
[in] | bytes | The sequence of bytes to write to the I2C slave. |
[in] | length | The number of bytes to write. |
[in] | ack | Whether or not an acknowledgment is expected from the slave. |
- Returns
- N/A.
The documentation for this class was generated from the following files: