My Project
 All Classes Functions Variables Pages
Public Member Functions | Static Public Attributes | List of all members
I2C Class Reference

Interface to I2C functions. More...

#include <I2C.h>

Public Member Functions

 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...
 

Static Public Attributes

static const gpio_num_t DEFAULT_SDA_PIN = GPIO_NUM_25
 The default SDA pin.
 
static const gpio_num_t DEFAULT_CLK_PIN = GPIO_NUM_26
 The default Clock pin.
 
static const uint32_t DEFAULT_CLK_SPEED = 100000
 The default Clock speed.
 

Detailed Description

Interface to I2C functions.

Constructor & Destructor Documentation

I2C::I2C ( )

Create an instance of an I2C object.

Returns
N/A.

Member Function Documentation

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.
void I2C::init ( uint8_t  address,
gpio_num_t  sdaPin = DEFAULT_SDA_PIN,
gpio_num_t  sclPin = DEFAULT_CLK_PIN,
uint32_t  clockSpeed = DEFAULT_CLK_SPEED,
i2c_port_t  portNum = I2C_NUM_0,
bool  pullup = true 
)

Initialize the I2C interface.

Parameters
[in]addressThe address of the slave device.
[in]sdaPinThe pin to use for SDA data.
[in]sclPinThe 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]bytesThe address into which the read bytes will be stored.
[in]lengthThe number of expected bytes to read.
[in]ackWhether 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]byteThe address into which the read byte will be stored.
[in]ackWhether or not we should send an ACK to the slave after reading a byte.
Returns
N/A.
void I2C::scan ( )

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]addressThe address of the I2C slave.
void I2C::setDebug ( bool  enabled)

enable or disable debugging.

Parameters
[in]enabledShould debugging be enabled or disabled.
Returns
N/A.
bool I2C::slavePresent ( uint8_t  address)

Determine if the slave is present and responding.

Parameters
[in]Theaddress of the slave.
Returns
True if the slave is present and false otherwise.
void I2C::start ( )

Add an I2C start request to the command stream.

Returns
N/A.
void I2C::stop ( )

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]byteThe byte to write to the slave.
[in]ackWhether 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]bytesThe sequence of bytes to write to the I2C slave.
[in]lengthThe number of bytes to write.
[in]ackWhether or not an acknowledgment is expected from the slave.
Returns
N/A.

The documentation for this class was generated from the following files: