NetBurner 3.5.6
PDF Version
TwoWire Class Reference

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.
 

Detailed Description

Wire interface class.

Constructor & Destructor Documentation

◆ TwoWire() [1/2]

TwoWire::TwoWire ( int mod)

Wire Constructor with specified module.

Parameters
modI2C module number

◆ TwoWire() [2/2]

TwoWire::TwoWire ( PinIO scl,
PinIO sda )

Constructor.

Parameters
sclSCL pin
sdaSDA pin

If BBI2C is defined, this will automatically use software I2C if the specified pins don't map to a hardware I2C deivce

Member Function Documentation

◆ available()

size_t TwoWire::available ( )

Check if any bytes are available to read.

Return values
Numberof bytes available in the buffer

◆ begin()

void TwoWire::begin ( uint8_t slave_addr = 0)

Initalize the system.

Parameters
slave_addrAddress of the target device

◆ beginTransmission()

void TwoWire::beginTransmission ( uint8_t address)

Set up a start for writing.

Parameters
addressAddress of the target device

◆ endTransmission()

int TwoWire::endTransmission ( bool bStop = true)

Do a stop with restart.

Parameters
bStopIf true, sends a stop message and releases the bus
Return values
0Success
1Data too big
2NACK on address
3NACK on data
4Other error
5Timeout

◆ onReceive()

void TwoWire::onReceive ( slave_rx_handler * handler)

Register a Receive callback (Does not work on the BBI2C software interface)

Parameters
handlerPointer to the function to call when bytes are received

◆ onRequest()

void TwoWire::onRequest ( slave_rq_handler * handler)

Register a Request callback (Does not work on the BBI2C software interface)

Parameters
handlerPointer to the function to call when bytes are requested

◆ ping()

bool TwoWire::ping ( uint8_t addr)

Check to see if addr exists on this bus.

Return values
trueif the address exists

◆ read() [1/2]

uint8_t TwoWire::read ( )
inline

Read the next byte from the buffer.

Return values
Onebyte of data from the buffer

◆ read() [2/2]

size_t TwoWire::read ( uint8_t * pbuf,
size_t maxlen )

Read available data up to maxlen bytes (Not a standard Wire function)

Parameters
pbufPointer to a buffer to read bytes into
maxlenMaximum number of bytes to read
Return values
0if no read data is available

◆ readReg8()

int TwoWire::readReg8 ( uint8_t dAddr,
uint32_t reg,
uint8_t & data )
inline

Read an 8-bit value from an I2C target device register.

Parameters
dAddrAddress of I2C device
regRegister address to read
dataReference to variable in which to store the register data
Returns
result code.

◆ readRegN()

int TwoWire::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.

Parameters
dAddrAddress of I2C device
regRegister address to read
*bufPointer to buffer to store received data
blenNumber of bytes to read
Returns
result code.

◆ requestFrom()

int TwoWire::requestFrom ( uint8_t address,
size_t quantity,
bool stop = true )

Request bytes from the target device.

Parameters
addressAddress of the target device
quantityHow many bytes to request
stopSet true to send a stop message and releases the bus when done, otherwise sends a restart
Return values
numberof bytes read

◆ setClock()

void TwoWire::setClock ( uint32_t clockbaud)
inline

Set baud rate.

Parameters
clockbaudBaud rate (default 200Khz)

◆ setWireTimeout()

void TwoWire::setWireTimeout ( int timeout_usec = 0,
bool reset_on_timeout = false )

Set the completion timeout.

Parameters
timeout_usecTimeout in microseconds
reset_on_timeoutSet true to reset the I2C system and unhang the bus upon timeout

◆ write() [1/4]

size_t TwoWire::write ( char v)
inline

Send a char to the target device.

Parameters
vCharacter to write
Return values
numberof bytes written

◆ write() [2/4]

size_t TwoWire::write ( const char * pStr,
int len = -1 )
inline

Send a string to the target device.

Parameters
pStrC-style string to send
lenLength of data
Return values
numberof bytes written

◆ write() [3/4]

size_t TwoWire::write ( const uint8_t * pdata,
int len )

Send data to the target device.

Parameters
pdataPointer to data to send
lenLength of data
Return values
numberof bytes written

◆ write() [4/4]

size_t TwoWire::write ( uint8_t v)
inline

Send an int to the target device.

Parameters
vInteger data to write
Return values
numberof bytes written

◆ writeReg8()

int TwoWire::writeReg8 ( uint8_t dAddr,
uint32_t reg,
uint8_t data )
inline

Write an 8-bit value to a I2C target device register.

Parameters
dAddrAddress of I2C device
regRegister address to write
dataData to write to register
Returns
result code

◆ writeRegN()

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.

Parameters
dAddrAddress of I2C device
regRegister address to write
*bufPointer to buffer containing data to write
blenNumber of bytes to write
Returns
result code.

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