TwoWire Class

TwoWire Class

Description
A class of I2C API.

Syntax
class TwoWire

Members

Public Constructors 
TwoWire::TwoWireConstructs a TwoWire object.
Public Methods 
TwoWire::beginInitialize I2C master/slave.
TwoWire::setClockSet I2C clock frequency.
TwoWire::beginTransmissionBegin I2C transmission.
TwoWire::endTransmissionStop I2C transmission.
TwoWire::requestFromSet I2C requestFrom.
TwoWire::writeWrite data to I2C.
TwoWire::availableCheck if I2C is available.
TwoWire::readRead data from I2C.
TwoWire::peekRead peek from I2C.
TwoWire::flushDo nothing, use, and transmission(..) to force data transfer.
TwoWire::onReceiveCallback function when I2C on receive.
TwoWire::onRequestCallback function when I2C on request.

TwoWire::TwoWire

Description
Constructs a TwoWire object.

Syntax
TwoWire(uint32_t dwSDAPin, uint32_t dwSCLPin);

Parameters
dwSDAPin: The pin number on Ameba board to be set as SDA pin.
dwSCLPin: The pin number on Ameba board to be set as SCL pin.

Returns
NA

Example Code
Example: MasterWriter
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/Wire/examples/master_writer/master_writer.ino)

Notes and Warnings
“Wire.h” must be included to use the class function.

TwoWire::begin

Description
Initialize I2C master/slave.

Syntax
void begin(void);
void begin(uint8_t address = 0);
void begin(int address);

Parameters
address: Set the I2C master mode with slave address value.

Returns
NA

Example Code
Example: MasterWriter
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/Wire/examples/master_writer/master_writer.ino)

Notes and Warnings
“Wire.h” must be included to use the class function.

TwoWire::setClock

Description
Set I2C clock frequency.

Syntax
void setClock(uint32_t frequency);

Parameters
frequency: The frequency values.

Returns
NA

Example Code
Example: MasterWriter
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/Wire/examples/master_writer/master_writer.ino)

Notes and Warnings
“Wire.h” must be included to use the class function.

TwoWire::beginTransmission

Description
Begin I2C transmission to device.

Syntax
void beginTransmission(uint8_t address);
void beginTransmission(int address);

Parameters
address: The transmission address.

Returns
NA

Example Code
Example: MasterWriter
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/Wire/examples/master_writer/master_writer.ino)

Notes and Warnings
“Wire.h” must be included to use the class function.

TwoWire::endTransmission

Description
Stop I2C transmission.

Syntax
uint8_t endTransmission(uint8_t sendStop);
uint8_t endTransmission(void);

Parameters
sendStop: True to end the transmission.

Returns
This function returns 0 if successful, else returns error.

Example Code
Example: MasterWriter
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/Wire/examples/master_writer/master_writer.ino)

Notes and Warnings
Originally, ‘endTransmission’ was an f(void) function. It has been modified to take one parameter indicating whether a STOP should be performed on the bus. Calling endTransmission(false) allows a sketch to perform a repeated start.
WARNING: Nothing in the library keeps track of whether the bus tenure has been properly ended with a STOP. It is very possible to leave the bus in a hung state if no call to endTransmission(true) is made. Some I2C devices will behave oddly if they do not see a STOP.
If the input parameter is void, this provides backward compatibility with the original definition, and expected behavior, of endTransmission.
“Wire.h” must be included to use the class function.

TwoWire::requestFrom

Description
Set I2C requestFrom.

Syntax
uint8_t requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop);
uint8_t requestFrom(uint8_t address, uint8_t quantity);
uint8_t requestFrom(int address, int quantity);
uint8_t requestFrom(int address, int quantity, int sendStop);

Parameters
address: I2C read address.
quantity: I2C read quantity.
sendStop: True to end the transmission.

Returns
This function returns 0 if successful, else returns error.

Example Code
Example: MasterReader
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/Wire/examples/master_reader/master_reader.ino)

Notes and Warnings
“Wire.h” must be included to use the class function.

TwoWire::write

Description
Write data to I2C.

Syntax
size_t write(uint8_t data);
size_t write(const uint8_t *data, size_t quantity);

Parameters
data: The data to be transmitted.
quantity: The quantity of data.

Returns
This function returns 0 if successful, else returns error.

Example Code
Example: MasterWriter
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/Wire/examples/master_writer/master_writer.ino)

Notes and Warnings
“Wire.h” must be included to use the class function.

TwoWire::available

Description
Check if I2C is available.

Syntax
virtual int available(void);

Parameters
NA

Returns
This function returns 0 if successful, else returns error.

Example Code
Example: MasterReader
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/Wire/examples/master_reader/master_reader.ino)

Notes and Warnings
“Wire.h” must be included to use the class function.

TwoWire::read

Description
Read data from I2C.

Syntax
virtual int read(void);

Parameters
NA

Returns
This function returns the data read from receiver buffer.

Example Code
Example: MasterReader
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/Wire/examples/master_reader/master_reader.ino)

Notes and Warnings
“Wire.h” must be included to use the class function.

TwoWire::peek

Description
Read peek from I2C.

Syntax
virtual int peek(void);

Parameters
NA

Returns
This function returns the peek data read from receiver buffer.

Example Code
Example: MasterReader
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/Wire/examples/master_reader/master_reader.ino)

Notes and Warnings
“Wire.h” must be included to use the class function.

TwoWire::flush

Description
Do nothing, use endTransmission(..) to force data transfer.

Syntax
virtual void flush(void);

Parameters
NA

Returns
NA

Example Code
NA

Notes and Warnings
“Wire.h” must be included to use the class function.

TwoWire::onReceive

Description
Callback function when I2C is on receive.

Syntax
void onReceive(void(*function)(int));

Parameters
function: The callback function.

Returns
NA

Example Code
NA

Notes and Warnings
“Wire.h” must be included to use the class function.

TwoWire::onRequest

Description
Callback function when I2C is on request.

Syntax
void onRequest(void(*function)(void));

Parameters
function: The callback function.

Returns
NA

Example Code
NA

Notes and Warnings
“Wire.h” must be included to use the class function.

Please confirm that QQ communication software is installed