Home

Awesome

HardWire Arduino Library V2.0

Licensing information is attached on the header of each file.

This is an I2C Arduino library, equivalent to the Arduino Wire lib, but with more functionality. This gives more control at the lower layer of the I2C protocol, without affecting the simplicity of the original library.

With the conventional Wire library, you can take action only after the STOP or when addressed as a Slave Transmit. In Hard Wire, the user can take a custom action in the following I2C states:

As a result, the user can take action at each step, in real time, of the I2C bus cycle where an example is depicted here below:

alt tag

How to use it

The HardWire lib instantiates a Wire object, so that if in the code were previously used the Wire, no changes are required, except for the header, which shall be "HardWire.h" instead of "Wire.h". When referring to the "data buffer" or "shared buffer", it is intended the buffer handled by the Wire, accessed only using the API from the Wire or HardWire library, which are the same.

Basically you can follow the official Wire guide, but also another description of the HardWire here. Here will be described only the differences between the original Wire and the HardWire, everything else is compliant with the guide linked above to the Wire.

Handlers

This "hardened" (or more "hardware", "hardwired") version also supports the following handlers assigned during the initialization (are listed also the official ones). Note that the use of the additional HardWire handlers is never mandatory.

Officials from original Wire

i.e.  void myHandler(int numBytes)
i.e. void myHandler()

New in the HardWire

i.e. void myHandler(unsigned char)
i.e. void myHandler()
i.e. void myHandler()
i.e. unsigned char myHandler()
i.e. void myHandler()

Initialization

This version supports a particular mode that shall be notified in the init. If omitted, it is initialized as the normal Wire.

New in the HardWire

Officials from original Wire

Notes

When registering the Wire.onRequestData(handler) handler, the slave transmit buffer will not be utilized. This means that in slave mode, with onRequestData() registered, writing to Wire.write() will not send anything to master when the master will request. The only way to send data to master while in this mode, is to use the retuned value from onRequestData(). Reading the data from the master in this mode will stay as per Wire library. :)