The I2C class represents an I²C two-wire serial port, of which the imp provides two.
The imp’s i2c objects are automatically instantiated at start-up, and are accessed on the imp001 and imp002 through hardware.i2c12 and hardware.i2c89. On the imp003 (Murata part number LBWA1ZV1CD), the i2c objects are accessed as hardware.i2cAB and hardware.i2cFG.
For the imp001 and imp002, pins 1 and 8 are assigned to each bus’ clock line (SCL); pins 2 and 9 are assigned to data (SDA). For the imp003, pins A and F are assigned to SCL; pins B and G to SDA.
For more information on every imp module’s pin-outs, see the imp pin mux.
When implementing I²C using an imp, please note that external pull-ups are required. It is not possible to enable the internal pull-ups when pins are used for I²C.
See the Developer Guide ‘I²C Explained’ for more information regarding the use of I²C devices with the imp.
The i2c object has the following member methods:
- i2c.configure(const) – Configures the I²C clock speed and enables the port.
- i2c.disable() – Disables the I²C bus.
- i2c.read(integer, string, integer) – Initiates an I²C read from a specific register within a specific device.
- i2c.readerror() – Returns the error code generated by the last I²C read.
- i2c.write(integer, string) – Initiates an I²C write to the device at the specified address.