Here is an introductory guide to starting your project involving I2C communication using an ultra-low-power MSP microcontroller (MCU):
I2C (or I2C, for Inter-Integrated Circuit) is a form of two-line communication used to communicate most commonly between microcontrollers and peripheral ICs at a low speed in short-distance, intra-board applications. Because of its widespread adoption, learning to use I2C communication with MSP MCUs has become essential for helping engineers develop their applications. This guide provides the tools and resources necessary to understand I2C protocol and implement it using an ultra-low-power MSP MCU to access and control IC devices.
The device driving the SCL clock line is called the master and the devices which respond to it are known as slaves. In most applications the MSP MCU is the master device and the peripheral ICs are the slaves, however there are times when the MSP device is a slave to other MCUs or processors.
The I2C bus consists of two wires, SCL and SDA. SCL is the clock line used to synchronize all data transfers and SDA is actual the data line. A third line, common GND, is also required but often not mentioned. Because both lines are “open drain” drivers they each require pull-up resistance to a power supply line so that the outputs remain high during no operation. For MSP MCU applications the supply voltage should match that of the MSP MCU’s Vcc. The value of the pull-up resistors is traditionally 4.7 kΩ but this value ranges from less than a kΩ to over 10 kΩ, depending on the slave devices used. Please refer to the device’s datasheet in order to use the correct pull-up resistance. Multiple slave devices can share an I2C bus using single pull-up resistors for the SCL and SDA lines.
I2C software protocol
Regardless of application each I2C-capable device is required to follow the software protocol commonly defined for all I2C devices, the general structure of which always remains the same. Communication begins with a start sequence and concludes with a stop sequence, with 8-bit data transfer sequences in between. A start bit is followed with the slave address, the length of which is typically seven bits (although in rare cases, 10-bit addressing is used). These seven bits are placed in the upper 7 bits of a byte and the LSB (Least Significant Bit) is used to store the Read/Write (R/W) bit. This bit lets the slave device know whether it will be written to (bit value zero) or read from (bit value one). For a write, the transaction sequence is as follows:
The read transaction sequence is very similar to that of a write, with the exception that instead of sending data bytes it will re-send the start sequence (known as a repeated start) and the slave address (although this time, with the R/W bit high for a read) so that it may receive data instead of sending it. The transaction is concluded after the master sends the typical stop sequence. Below is the read transaction sequence:
MSP MCU communication peripherals
There are four different possible peripherals available on MSP devices to realize serial communication. Only one of these will exist per device. In order of ease by which they can be used to realize I2C communication on a MSP MCU, from hardest to easiest, they are listed as such:
When selecting an MSP device with I2C applications in mind one should understand that the code structure varies depending upon the peripheral existent on the specific MSP derivative. Each variant includes different registers, ISRs, and functions that must be taken into account. It must also be made clear that not all device families use the same peripheral (USCI and eUSCI exists in the MSP430F5xx/6xx family, USI and USCI exists in the MSP430G2xx family, etc) which can be quite confusing when referring to the Family User’s Guide. Therefore caution must be taken into account to view the correct material and select the correct example code upon which to start developing one’s application. Texas Instruments provides basic I2C code examples for USI, USCI, and eUSCI communication which can be found on the MSP derivative’s product page under Tools & software -> Software -> Examples (available as a ZIP file, note that these packages only contain the code examples relevant to the peripherals that exist on the particular device). For devices which use USART or do not include a communication peripheral, I2C bit-bang solutions are provided online through community effort. Regardless of peripheral used, pull-up resistors will always be required to accomplish I2C communication. Some MSP devices have internal pull-up resistors but use of these is not recommended as several slave devices require a particular resistance not accommodated internally.
Tips for Implementing I2C with the MSP
When attempting to communicate between a peripheral IC and MSP using I2C, here are some suggestions that should be reviewed to help avoid common implementation errors:
Before giving up on code that doesn’t seem to operate correctly, here are some checkpoints to consider for debugging the system:
If proper debugging and research methods have failed, the TI E2E community forum can be a great resource for directly communicating with device experts. Make sure to include detailed information regarding all aspects of the issue at hand to help community members and TI engineers better service the request, including:
Migrating from the USCI Module to the eUSCI Module (SLAA522): http://www.ti.com/lit/an/slaa522a/slaa522a.pdf
Using the USCI I2C Master (SLAA382): http://www.ti.com/lit/an/slaa382a/slaa382a.pdf
Using the USCI I2C Slave (SLAA383): http://www.ti.com/lit/an/slaa383/slaa383.pdf
Using the I2C Bus (blog): http://www.robot-electronics.co.uk/i2c-tutorial
Very good post.
All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.