Wire Library (I2C)

Overview

This library allows you to communicate with I2C / TWI devices. The library inherits from the Stream functions, making it consistent with other read/write libraries. I2C is a two wire interface using the SDA (Serial Data Line) and SCL (Serial Clock Line) pins to communicate over the serial bus. I2C uses a multi-master/multi-slave model where the master generates the clock and initiates communication with the slaves. A slave receives the clock and responds when addressed by the master. I2C is a common interface between a microcontroller and peripherals like sensors and displays.

Some LaunchPad’s support multiple Wire interfaces on different pins. These can be addressed by WireX where X is a number. For example, the MSP432 LaunchPad supports Wire and Wire1. Wire is on pins 9 and 10 where Wire1 is on pins 14 and 15. Please see the pinmap for each LaunchPad for details about the availability of additional instances of Wire and the pins associated with it.

There are both 7- and 8-bit versions of I2C addresses. 7 bits identify the device, and the eighth bit determines if it’s being written to or read from. The Wire library uses 7 bit addresses throughout. If you have a datasheet or sample code that uses 8 bit address, you’ll want to drop the low bit (i.e. shift the value one bit to the right), yielding an address between 0 and 127.

Applications

I2C is common in segment LCDs and different types of sensors. I2C is lower speed than some other protocols but is still very effective in communicating with multiple devices on one bus. Popular alternative protocols are SPI and UART

Guide Home