I2C Test

The LaunchPad BoosterPack incorporates several peripherals which communicate over an I2C interface. I2C is a simple 2 wire shared bus that is useful for low speed (400kHz - 1MHz) peripherals. We use it to communicate with a color sensor, IR temperature sensor, and EEPROM. We wrote the I2C Test example when doing the initial development and found that it was so useful when working with I2C that we decided to include it in the release. The example performs several useful functions:
 * 1) Initialize the I2C bus
 * 2) Search for All I2C peripherals
 * 3) Initialize the TMP006 IR temperature sensor
 * 4) Initialize the Color Sensor
 * 5) Initialize the EEPROM
 * 6) Read the IR Temperature
 * 7) Read the Color
 * 8) Test the EEPROM:
 * 9) Write to a byte
 * 10) Read a byte
 * 11) Write a page
 * 12) Read a page
 * 13) Read a sequential address

This example is an example of a good firmware design pattern of abstracting the driver code from the application. Placing the code that communicates over the I2C bus into a separate file from the application makes it easier to troubleshoot and also easier to reuse code.

If you are adding on your own I2C peripheral then run this example and verify that the I2C bus address of your peripheral is found.



Under the Hood
This example demonstrates abstraction. You'll notice that the application only includes peripheral-specific files: The example does not include any I2C driver code; this is all in the peripheral-specific files. For example, in hal_TI_TMP006_IR_temperature_sensor.h it includes hal.h. This file in turn includes our underlying I2C driver which is device dependent. For example: This also demonstrates the power of using a consistent API - it allows you to use the same code across multiple platforms. Both hal_stellaris_softi2c.h (for Stellaris/Tiva) and hal_bit_bang_i2c.h (for MSP430) share the same method signatures.
 * hal_TI_TMP006_IR_temperature_sensor.h
 * hal_AMS_TCS3414_color_sensor.h
 * hal_Microchip_24xxxxx_eeprom.h
 * Stellaris/Tiva: hal_stellaris_softi2c.h
 * MSP430 Launchpad: hal_bit_bang_i2c.h

History
This example has been available since Version 1880.

Next Example: Read Color Sensor

Previous: Hello World

Top: Module_Examples