NetBurner 3.3.9
PDF Version
WireIntf Class Reference

Wire Interface Class for I2C. More...

#include <i2c.h>

Public Member Functions

void begin ()
 Initialize the WireIntf driver object as a master with a bus speed of 100 kHz. This normally only needs to be called once.
 
uint32_t requestFrom (uint8_t addr, uint32_t len, bool stop=true)
 Request a number of bytes from a slave device. The bytes can then be retrieved from the slave device with the read() and available() functions. More...
 
void beginTransmission (uint8_t addr)
 Begin a transmission to a I2C slave device at the provided address. Bytes can be queued for transmission with the write() functions, and are transmitted by calling endTransmission(). More...
 
void endTransmission (bool stop=true)
 Transmits the bytes of data queued by using the write() functions, and ends a transmission to a slave device that was started using beginTransmission(). More...
 
uint32_t write (uint8_t dat)
 Queues bytes of data to be transmitted to the slave device. This function can be called after a call to beginTransmission(). The data will not be transmitted on the I2C bus until a call to endTransmission() or flush() is performed. More...
 
uint32_t write (char *str)
 Queues bytes of data to be transmitted to the slave device. This function can be called after a call to beginTransmission(). The data will not be transmitted on the I2C bus until a call to endTransmission() or flush() is performed. More...
 
uint32_t write (uint8_t *buf, uint32_t len)
 Queues bytes of data to be transmitted to the slave device. This function can be called after a call to beginTransmission(). The data will not be transmitted on the I2C bus until a call to endTransmission() or flush() is performed. More...
 
uint32_t available ()
 Get the number of bytes available to be read from the slave device with read(). This function can be called after a call to requestFrom(). More...
 
uint8_t read ()
 Reads a byte of data that was transmitted from a slave I2C device after a call to requestFrom(). More...
 
void flush (bool bIssueStop=false)
 Force the data that were queued to be transmitted using the write() functions to be transmitted on the I2C bus. More...
 

Detailed Description

Wire Interface Class for I2C.

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

Member Function Documentation

◆ available()

uint32_t WireIntf::available ( )

Get the number of bytes available to be read from the slave device with read(). This function can be called after a call to requestFrom().

Returns
The number of bytes available for reading from the slave device.

◆ beginTransmission()

void WireIntf::beginTransmission ( uint8_t  addr)

Begin a transmission to a I2C slave device at the provided address. Bytes can be queued for transmission with the write() functions, and are transmitted by calling endTransmission().

Parameters
addrthe address of the device to transmit data to.

◆ endTransmission()

void WireIntf::endTransmission ( bool  stop = true)

Transmits the bytes of data queued by using the write() functions, and ends a transmission to a slave device that was started using beginTransmission().

Parameters
stopIf true, sends a stop message after the request, releasing the I2C bus. If false, the driver will send a restart request, keeping the connection alive. This prevents other I2C master devices from transmitting between messages. This allows one master to transmit multiple transmissions uninterrupted.

◆ flush()

void WireIntf::flush ( bool  bIssueStop = false)

Force the data that were queued to be transmitted using the write() functions to be transmitted on the I2C bus.

If you need to know exactly when a transaction will occur, call flush(). If accessing a register, be sure to write all address bytes before the call.

Parameters
bIssueStopIf true, sends a stop message after the request, releasing the I2C bus. If false, the driver will send a restart request, keeping the connection alive. This prevents other I2C master devices from transmitting between messages. This allows one master to transmit multiple transmissions uninterrupted.

◆ read()

uint8_t WireIntf::read ( )

Reads a byte of data that was transmitted from a slave I2C device after a call to requestFrom().

Returns
The byte of data received from the slave I2C device.

◆ requestFrom()

uint32_t WireIntf::requestFrom ( uint8_t  addr,
uint32_t  len,
bool  stop = true 
)

Request a number of bytes from a slave device. The bytes can then be retrieved from the slave device with the read() and available() functions.

Parameters
addrthe address of the slave to request data from.
lenthe number of bytes to request from the slave.
stopIf true, sends a stop message after the request, releasing the I2C bus. If false, the driver will send a restart request, keeping the connection alive. This prevents other I2C master devices from transmitting between messages. This allows one master to transmit multiple transmissions uninterrupted.
Returns
The number of bytes returned from the slave I2C device.

◆ write() [1/3]

uint32_t WireIntf::write ( char *  str)

Queues bytes of data to be transmitted to the slave device. This function can be called after a call to beginTransmission(). The data will not be transmitted on the I2C bus until a call to endTransmission() or flush() is performed.

Parameters
strA string to send as a series of bytes to the I2C slave device.
Returns
The number of of bytes written to the transmit queue buffer.

◆ write() [2/3]

uint32_t WireIntf::write ( uint8_t *  buf,
uint32_t  len 
)

Queues bytes of data to be transmitted to the slave device. This function can be called after a call to beginTransmission(). The data will not be transmitted on the I2C bus until a call to endTransmission() or flush() is performed.

Parameters
bufAn array of data to send as bytes to the I2C slave device.
lenThe number of bytes to be written from the buf parameter.
Returns
The number of of bytes written to the transmit queue buffer.

◆ write() [3/3]

uint32_t WireIntf::write ( uint8_t  dat)

Queues bytes of data to be transmitted to the slave device. This function can be called after a call to beginTransmission(). The data will not be transmitted on the I2C bus until a call to endTransmission() or flush() is performed.

Parameters
datA byte of data to be transmitted to the I2C slave device.
Returns
The number of of bytes written to the transmit queue buffer.

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