< The class which defines how we will talk to this device over I2C
More...
#include <Adafruit_I2CDevice.h>
|
| Adafruit_I2CDevice (uint8_t addr, TwoWire *theWire=&Wire) |
| Create an I2C device at a given address. More...
|
|
uint8_t | address (void) |
| Returns the 7-bit address of this device. More...
|
|
bool | begin (bool addr_detect=true) |
| Initializes and does basic address detection. More...
|
|
void | end (void) |
| De-initialize device, turn off the Wire interface.
|
|
bool | detected (void) |
| Scans I2C for the address - note will give a false-positive if there's no pullups on I2C. More...
|
|
bool | read (uint8_t *buffer, size_t len, bool stop=true) |
| Read from I2C into a buffer from the I2C device. Cannot be more than maxBufferSize() bytes. More...
|
|
bool | write (const uint8_t *buffer, size_t len, bool stop=true, const uint8_t *prefix_buffer=nullptr, size_t prefix_len=0) |
| Write a buffer or two to the I2C device. Cannot be more than maxBufferSize() bytes. More...
|
|
bool | write_then_read (const uint8_t *write_buffer, size_t write_len, uint8_t *read_buffer, size_t read_len, bool stop=false) |
| Write some data, then read some data from I2C into another buffer. Cannot be more than maxBufferSize() bytes. The buffers can point to same/overlapping locations. More...
|
|
bool | setSpeed (uint32_t desiredclk) |
| Change the I2C clock speed to desired (relies on underlying Wire support! More...
|
|
size_t | maxBufferSize () |
| How many bytes we can read in a transaction. More...
|
|
< The class which defines how we will talk to this device over I2C
◆ Adafruit_I2CDevice()
Adafruit_I2CDevice::Adafruit_I2CDevice |
( |
uint8_t |
addr, |
|
|
TwoWire * |
theWire = &Wire |
|
) |
| |
Create an I2C device at a given address.
- Parameters
-
addr | The 7-bit I2C address for the device |
theWire | The I2C bus to use, defaults to &Wire |
◆ address()
uint8_t Adafruit_I2CDevice::address |
( |
void |
| ) |
|
Returns the 7-bit address of this device.
- Returns
- The 7-bit address of this device
◆ begin()
bool Adafruit_I2CDevice::begin |
( |
bool |
addr_detect = true | ) |
|
Initializes and does basic address detection.
- Parameters
-
addr_detect | Whether we should attempt to detect the I2C address with a scan. 99% of sensors/devices don't mind, but once in a while they don't respond well to a scan! |
- Returns
- True if I2C initialized and a device with the addr found
◆ detected()
bool Adafruit_I2CDevice::detected |
( |
void |
| ) |
|
Scans I2C for the address - note will give a false-positive if there's no pullups on I2C.
- Returns
- True if I2C initialized and a device with the addr found
◆ read()
bool Adafruit_I2CDevice::read |
( |
uint8_t * |
buffer, |
|
|
size_t |
len, |
|
|
bool |
stop = true |
|
) |
| |
Read from I2C into a buffer from the I2C device. Cannot be more than maxBufferSize() bytes.
- Parameters
-
buffer | Pointer to buffer of data to read into |
len | Number of bytes from buffer to read. |
stop | Whether to send an I2C STOP signal on read |
- Returns
- True if read was successful, otherwise false.
◆ write()
bool Adafruit_I2CDevice::write |
( |
const uint8_t * |
buffer, |
|
|
size_t |
len, |
|
|
bool |
stop = true , |
|
|
const uint8_t * |
prefix_buffer = nullptr , |
|
|
size_t |
prefix_len = 0 |
|
) |
| |
Write a buffer or two to the I2C device. Cannot be more than maxBufferSize() bytes.
- Parameters
-
buffer | Pointer to buffer of data to write. This is const to ensure the content of this buffer doesn't change. |
len | Number of bytes from buffer to write |
prefix_buffer | Pointer to optional array of data to write before buffer. Cannot be more than maxBufferSize() bytes. This is const to ensure the content of this buffer doesn't change. |
prefix_len | Number of bytes from prefix buffer to write |
stop | Whether to send an I2C STOP signal on write |
- Returns
- True if write was successful, otherwise false.
◆ write_then_read()
bool Adafruit_I2CDevice::write_then_read |
( |
const uint8_t * |
write_buffer, |
|
|
size_t |
write_len, |
|
|
uint8_t * |
read_buffer, |
|
|
size_t |
read_len, |
|
|
bool |
stop = false |
|
) |
| |
Write some data, then read some data from I2C into another buffer. Cannot be more than maxBufferSize() bytes. The buffers can point to same/overlapping locations.
- Parameters
-
write_buffer | Pointer to buffer of data to write from |
write_len | Number of bytes from buffer to write. |
read_buffer | Pointer to buffer of data to read into. |
read_len | Number of bytes from buffer to read. |
stop | Whether to send an I2C STOP signal between the write and read |
- Returns
- True if write & read was successful, otherwise false.
◆ setSpeed()
bool Adafruit_I2CDevice::setSpeed |
( |
uint32_t |
desiredclk | ) |
|
Change the I2C clock speed to desired (relies on underlying Wire support!
- Parameters
-
desiredclk | The desired I2C SCL frequency |
- Returns
- True if this platform supports changing I2C speed. Not necessarily that the speed was achieved!
◆ maxBufferSize()
size_t Adafruit_I2CDevice::maxBufferSize |
( |
| ) |
|
|
inline |
How many bytes we can read in a transaction.
- Returns
- The size of the Wire receive/transmit buffer
The documentation for this class was generated from the following files: