The I2C class represents an I²C two-wire serial port, of which the imp provides two.
The imp’s i2c objects are 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), in keeping with this module’s unique pin designations, 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 of N bytes from the specified base and sub-address
- i2c.readerror() – returns error code from last I²C read
- i2c.write(integer, string) – initiates an I²C write to the specified address