NetBurner 3.5.6
PDF Version |
Wire interface class. More...
#include <Wire.h>
Public Member Functions | |
TwoWire (void) | |
Wire Constructor with platform default I2C module. | |
TwoWire (int mod) | |
Wire Constructor with specified module. | |
TwoWire (PinIO scl, PinIO sda) | |
Constructor. | |
void | setClock (uint32_t clockbaud) |
Set baud rate. | |
void | begin (uint8_t slave_addr=0) |
Initalize the system. | |
void | end () |
Turn system off. | |
void | beginTransmission (uint8_t address) |
Set up a start for writing. | |
int | endTransmission (bool bStop=true) |
Do a stop with restart. | |
size_t | write (const uint8_t *pdata, int len) |
Send data to the target device. | |
size_t | write (char v) |
Send a char to the target device. | |
size_t | write (uint8_t v) |
Send an int to the target device. | |
size_t | write (const char *pStr, int len=-1) |
Send a string to the target device. | |
int | requestFrom (uint8_t address, size_t quantity, bool stop=true) |
Request bytes from the target device. | |
size_t | available () |
Check if any bytes are available to read. | |
size_t | read (uint8_t *pbuf, size_t maxlen) |
Read available data up to maxlen bytes (Not a standard Wire function) | |
uint8_t | read () |
Read the next byte from the buffer. | |
Target functions | |
void | onReceive (slave_rx_handler *handler) |
Register a Receive callback (Does not work on the BBI2C software interface) | |
void | onRequest (slave_rq_handler *handler) |
Register a Request callback (Does not work on the BBI2C software interface) | |
void | setWireTimeout (int timeout_usec=0, bool reset_on_timeout=false) |
Set the completion timeout. | |
void | clearTimeout () |
Clear the completion timeout. | |
bool | getWireTimeoutFlag () |
Get whether there is a completion timeout set. | |
Non-standard extensions | |
void | reset () |
Reset the I2C system and unhang the bus. | |
bool | ping (uint8_t addr) |
Check to see if addr exists on this bus. | |
int | writeRegN (uint8_t dAddr, uint32_t reg, const uint8_t *buf, uint32_t blen) |
Write a number of 8-bit values to an I2C slave to the specified register address. | |
int | readRegN (uint8_t dAddr, uint32_t reg, uint8_t *buf, uint32_t blen) |
Read a number of 8-bit values from an I2C slave at the specified register address. | |
int | writeReg8 (uint8_t dAddr, uint32_t reg, uint8_t data) |
Write an 8-bit value to a I2C target device register. | |
int | readReg8 (uint8_t dAddr, uint32_t reg, uint8_t &data) |
Read an 8-bit value from an I2C target device register. | |
Wire interface class.
TwoWire::TwoWire | ( | int | mod | ) |
Wire Constructor with specified module.
mod | I2C module number |
size_t TwoWire::available | ( | ) |
Check if any bytes are available to read.
Number | of bytes available in the buffer |
void TwoWire::begin | ( | uint8_t | slave_addr = 0 | ) |
Initalize the system.
slave_addr | Address of the target device |
void TwoWire::beginTransmission | ( | uint8_t | address | ) |
Set up a start for writing.
address | Address of the target device |
int TwoWire::endTransmission | ( | bool | bStop = true | ) |
Do a stop with restart.
bStop | If true, sends a stop message and releases the bus |
0 | Success |
1 | Data too big |
2 | NACK on address |
3 | NACK on data |
4 | Other error |
5 | Timeout |
void TwoWire::onReceive | ( | slave_rx_handler * | handler | ) |
Register a Receive callback (Does not work on the BBI2C software interface)
handler | Pointer to the function to call when bytes are received |
void TwoWire::onRequest | ( | slave_rq_handler * | handler | ) |
Register a Request callback (Does not work on the BBI2C software interface)
handler | Pointer to the function to call when bytes are requested |
bool TwoWire::ping | ( | uint8_t | addr | ) |
Check to see if addr exists on this bus.
true | if the address exists |
|
inline |
Read the next byte from the buffer.
One | byte of data from the buffer |
size_t TwoWire::read | ( | uint8_t * | pbuf, |
size_t | maxlen ) |
Read available data up to maxlen bytes (Not a standard Wire function)
pbuf | Pointer to a buffer to read bytes into |
maxlen | Maximum number of bytes to read |
0 | if no read data is available |
|
inline |
int TwoWire::readRegN | ( | uint8_t | dAddr, |
uint32_t | reg, | ||
uint8_t * | buf, | ||
uint32_t | blen ) |
int TwoWire::requestFrom | ( | uint8_t | address, |
size_t | quantity, | ||
bool | stop = true ) |
Request bytes from the target device.
address | Address of the target device |
quantity | How many bytes to request |
stop | Set true to send a stop message and releases the bus when done, otherwise sends a restart |
number | of bytes read |
|
inline |
Set baud rate.
clockbaud | Baud rate (default 200Khz) |
void TwoWire::setWireTimeout | ( | int | timeout_usec = 0, |
bool | reset_on_timeout = false ) |
Set the completion timeout.
timeout_usec | Timeout in microseconds |
reset_on_timeout | Set true to reset the I2C system and unhang the bus upon timeout |
|
inline |
Send a char to the target device.
v | Character to write |
number | of bytes written |
|
inline |
Send a string to the target device.
pStr | C-style string to send |
len | Length of data |
number | of bytes written |
size_t TwoWire::write | ( | const uint8_t * | pdata, |
int | len ) |
Send data to the target device.
pdata | Pointer to data to send |
len | Length of data |
number | of bytes written |
|
inline |
Send an int to the target device.
v | Integer data to write |
number | of bytes written |
|
inline |
int TwoWire::writeRegN | ( | uint8_t | dAddr, |
uint32_t | reg, | ||
const uint8_t * | buf, | ||
uint32_t | blen ) |
Write a number of 8-bit values to an I2C slave to the specified register address.
Executing this function will send the following: a start bit, the target device address and read/write bit, the 8-bit data bytes, and finally a stop bit. Note that the address is not incremented with each 8-bit data value.
dAddr | Address of I2C device |
reg | Register address to write |
*buf | Pointer to buffer containing data to write |
blen | Number of bytes to write |