TwoWire Class Reference

Class definition for the Arduino Wire library implementation. More...

Detailed Description

Class definition for the Arduino Wire library implementation.

Definition at line 70 of file wireport.hpp.

#include <wireport.hpp>

Public Member Functions

 TwoWire (void)
 Constructor.
 
void begin (void)
 Initializes the I2C device defined by ARDUINO_I2C_DEV as master.
 
void begin (uint8_t addr)
 Initializes the I2C device defined by ARDUINO_I2C_DEV as slave. More...
 
void setClock (uint32_t clk)
 Set the clock speed of the I2C device defined by ARDUINO_I2C_DEV. More...
 
void beginTransmission (uint8_t addr)
 Begin a transmission to a I2C slave device. More...
 
uint8_t endTransmission (void)
 End a transmission to a I2C slave device. More...
 
uint8_t endTransmission (uint8_t stop)
 End a transmission to a I2C slave device. More...
 
uint8_t requestFrom (uint8_t addr, uint8_t size)
 Request bytes from a I2C slave device. More...
 
uint8_t requestFrom (uint8_t addr, uint8_t size, uint8_t stop)
 Request bytes from a I2C slave device. More...
 
virtual size_t write (uint8_t data)
 Queue a byte for transmission from a master to slave device. More...
 
virtual size_t write (const uint8_t *data, size_t size)
 Queue bytes for transmission from a master to slave device. More...
 
virtual int available (void)
 Return the number of bytes available for retrieval. More...
 
virtual int read (void)
 Reads one byte transmitted from slave device to the master. More...
 
virtual size_t readBytes (uint8_t *buffer, size_t length)
 Read bytes transmitted from slave device to the master. More...
 
virtual int peek (void)
 Peeks one byte transmitted from slave device to the master. More...
 
virtual void flush (void)
 Flush the RX and TX buffer. More...
 

Member Function Documentation

◆ available()

virtual int TwoWire::available ( void  )
virtual

Return the number of bytes available for retrieval.

Returns the number of bytes available for retrieval with read. This should be called on a master device after a call to requestFrom.

Copied from https://www.arduino.cc/en/Reference/WireAvailable

Returns
number of bytes available for retrieval

◆ begin()

void TwoWire::begin ( uint8_t  addr)

Initializes the I2C device defined by ARDUINO_I2C_DEV as slave.

Note
Since slave mode is not yet supported by the RIOT port of the Arduino Wire library, calling this method leads to a core panic.
Parameters
[in]addrAddress of the device initialized as slave

◆ beginTransmission()

void TwoWire::beginTransmission ( uint8_t  addr)

Begin a transmission to a I2C slave device.

This method begins a transmission to the I2C slave device with the given address. Subsequently, queue bytes for transmission with the write method and transmit them by calling endTransmission.

Copied from https://www.arduino.cc/en/Reference/WireBeginTransmission

Parameters
[in]addrAddress of the slave device

◆ endTransmission() [1/2]

uint8_t TwoWire::endTransmission ( void  )

End a transmission to a I2C slave device.

Ends a transmission to a slave device that was begun by beginTransmission() and transmits the bytes that were queued by write. Sends always a STOP condition after the request.

Copied from https://www.arduino.cc/en/Reference/WireEndTransmission

Return values
0success
1data too long to fit in transmit buffer
2received NACK on transmit of address
3received NACK on transmit of data
4other error

◆ endTransmission() [2/2]

uint8_t TwoWire::endTransmission ( uint8_t  stop)

End a transmission to a I2C slave device.

Ends a transmission to a slave device that was begun by beginTransmission() and transmits the bytes that were queued by write.

Copied from https://www.arduino.cc/en/Reference/WireEndTransmission

Parameters
stopSend STOP condition after transmission if true or nothing if false.
Return values
0success
1data too long to fit in transmit buffer
2received NACK on transmit of address
3received NACK on transmit of data
4other error

◆ flush()

virtual void TwoWire::flush ( void  )
virtual

Flush the RX and TX buffer.

This method clears the RX as well as the TX buffer. It is not necessary to call this method explicitly. RX buffer is flushed implicitly when method requestFrom is called. Tx buffer is flushed implicitly when method beginTransmission is called.

◆ peek()

virtual int TwoWire::peek ( void  )
virtual

Peeks one byte transmitted from slave device to the master.

Reads a byte that was transmitted from a slave device to the master after a call to requestFrom without advancing to the next one. That is, successive calls to peek will return the same value, as will the next call to read.

Copied from https://www.arduino.cc/en/Reference/WireRead and https://www.arduino.cc/en/Reference/StreamPeek

Returns
next byte received, or -1 if none is available.

◆ read()

virtual int TwoWire::read ( void  )
virtual

Reads one byte transmitted from slave device to the master.

Reads a byte that was transmitted from a slave device to the master after a call to requestFrom and removes it from receive buffer.

Copied from https://www.arduino.cc/en/Reference/WireRead

Returns
next byte received, or -1 if none is available.

◆ readBytes()

virtual size_t TwoWire::readBytes ( uint8_t *  buffer,
size_t  length 
)
virtual

Read bytes transmitted from slave device to the master.

Reads a number of bytes that were transmitted from a slave device to the master after a call to requestFrom and removes them from receive buffer.

Parameters
[out]bufferbuffer to store the bytes
[in]lengthnumber of bytes to read
Returns
number of bytes placed in the buffer

◆ requestFrom() [1/2]

uint8_t TwoWire::requestFrom ( uint8_t  addr,
uint8_t  size 
)

Request bytes from a I2C slave device.

Used by the master to request bytes from a slave device. The bytes may then be retrieved with the available and read methods. Sends always a STOP condition after the request.

Copied from https://www.arduino.cc/en/Reference/WireRequestFrom

Parameters
[in]addr7-bit address of the device to request bytes from
[in]sizeNumber of bytes to request
Returns
number of bytes returned from the slave device

◆ requestFrom() [2/2]

uint8_t TwoWire::requestFrom ( uint8_t  addr,
uint8_t  size,
uint8_t  stop 
)

Request bytes from a I2C slave device.

Used by the master to request bytes from a slave device. The bytes may then be retrieved with the available and read methods.

Parameters
[in]addr7-bit address of the device to request bytes from
[in]sizeNumber of bytes to request
[in]stopSend STOP condition after the request if true or nothing if false.

Copied from https://www.arduino.cc/en/Reference/WireRequestFrom

Returns
number of bytes returned from the slave device

◆ setClock()

void TwoWire::setClock ( uint32_t  clk)

Set the clock speed of the I2C device defined by ARDUINO_I2C_DEV.

Note
In RIOT, the I2C bus clock speed is determined by the board definition. This method does therefore nothing. It is just realized for compatibility reasons.
Parameters
[in]clkI2C clock speed in Hz

◆ write() [1/2]

virtual size_t TwoWire::write ( uint8_t  data)
virtual

Queue a byte for transmission from a master to slave device.

The method queues a byte for transmission from a master to slave device in-between calls to beginTransmission and endTransmission.

Parameters
[in]dataData byte

Copied from https://www.arduino.cc/en/Reference/WireWrite

Returns
number of bytes queued

◆ write() [2/2]

virtual size_t TwoWire::write ( const uint8_t *  data,
size_t  size 
)
virtual

Queue bytes for transmission from a master to slave device.

The method queues bytes for transmission from a master to slave device in-between calls to beginTransmission and endTransmission.

Parameters
[in]dataArray of data to send as bytes
[in]sizeNumber of bytes to transmit

Copied from https://www.arduino.cc/en/Reference/WireWrite

Returns
number of bytes queued

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