NetBurner 3.5.0
PDF Version |
|
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. | |
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(). | |
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(). | |
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. | |
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. | |
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. | |
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(). | |
uint8_t | read () |
Reads a byte of data that was transmitted from a slave I2C device after a call to requestFrom(). | |
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. | |
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].
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().
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().
addr | the address of the device to transmit data to. |
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().
stop | If 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. |
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.
bIssueStop | If 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. |
uint8_t WireIntf::read | ( | ) |
Reads a byte of data that was transmitted from a slave I2C device after a call to 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.
addr | the address of the slave to request data from. |
len | the number of bytes to request from the slave. |
stop | If 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. |
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.
str | A string to send as a series of bytes to the I2C slave device. |
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.
buf | An array of data to send as bytes to the I2C slave device. |
len | The number of bytes to be written from the buf parameter. |
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.
dat | A byte of data to be transmitted to the I2C slave device. |