Please note as of Wednesday, August 15th, 2018 this wiki has been set to read only. If you are a TI Employee and require Edit ability please contact x0211426 from the company directory.

CC3200 I2C Application

From Texas Instruments Wiki
Jump to: navigation, search
Cc31xx cc32xx return home.png
Cc32xx return sample apps.png


The Inter-Integrated Circuit (I2C) bus provides bi-directional data transfer through a two-wire design (a serial data line SDA and a serial clock line SCL),and interfaces to external I2C devices.On the LaunchPad there are two sensors connected over the I2C namely Accelerometer and Temperature sensor. The I2C lines are also brought out on the header for further expansion (to connect to sensors on booster packs).

Application details

The objective of this application is act as an I2C diagnostic tool. The demo application is a generic implementation that allows the user to communicate with any I2C device over the lines.
The features supported by the application are:

  • I2C write: Performs write operation to the specifed I2C device address. User also needs to specify if the stop bit needs to be set or not (To support specifying and reading from a particular register).
  • I2C Read: Performs I2C read from the specified I2C device address.
  • I2C Readreg: Is a combination of I2C write (without stop bit) + I2C read. This is useful to get register values from the specified register offset from a I2C device.

This command assumes the register offset to be 1 byte.

  • I2C Writereg: Performs an I2C writes from the specified offset register. This command assumes the register offset to be 1 byte.

NoteNote: The write and read are core APIs that follow the I2C specification for its operation. They are generic and can be used to communicate with any I2C device.

NoteNote: The readreg and writereg are ready to use APIsthat internally invoke the read and write functionality. These have been provided for ease of use and is not guaranteed to work for all I2C devices due to some assumptions made.

Source Files briefly explained

  • main: - Prompts and services the user options by invoking the i2c_if APIs.
  • i2c_if: - I2C access interface APIs. This works in a polled mode of operation.
  • pinmux: - Pinmux configurations as required by the application.
  • startup_*: - Tool specific vector table implementation.
  • uart_if: - To display status information over the UART


NoteNote: For this application to work, one needs to populate jumpers at j2 and j3 on LP 3.x

  1. Setup a serial communication application (HyperTerminal/TeraTerm). For detail info visit Terminal setup
    On the host PC, open a hyperterminal, with the following settings
    • Port: 2nd enumerated COM port
    • Baud rate: 115200
    • Data: 8 bit
    • Parity: None
    • Stop: 1 bit
    • Flow control: None
  2. Run the reference application (Flashing the bin/IAR/CCS).
    • Open the Project as mentioned in the 'docs\CC3200-Getting Started Guide.pdf'
    • Build and download the application to the board
  3. On the Hyperterminal, a prompt appears
    • The I2C commands need to be issued and the results can be seen

CC3200 I2C Example Usage


write <dev_addr> <wrlen> <<byte0> [<byte1> ... ]> <stop>
read <dev_addr> <rdlen>
writereg <dev_addr> <reg_offset> <wrlen> <<byte0> [<byte1> ... ]>
readreg <dev_addr> <reg_offset> <rdlen>


           dev_addr - slave address of the i2c device, a hex value preceeded by '0x'
           reg_offset - register address in the i2c device, a hex value preceeded by '0x'

           wrlen - number of bytes to be written, a decimal value
           rdlen - number of bytes to be read, a decimal value

           bytex - value of the data to be written, a hex value preceeded by '0x'

           stop - number of stop bits, 0 or 1

NoteNote: The user can determine the device address of a particular component by looking at its respective datasheet.

  • The temperature sensor used is tmp006, and its device address (dev_addr) is 0x41
  • The accelerometer sensor used is bma222, and its device address (dev_addr) is 0x18

For instance

  • To read the manufacturer id register (0xFE) of the temperature sensor (0x41), the command will be
readreg 0x41 0xFE 2

  • To read the "who am i" register (0x00) of the accelerometer sensor (0x18), the command will be
readreg 0x18 0x00 1

Snapshot of the Hyperterminal when the application starts.

screen shot from teraterm

Limitations/Known Issues

  1. This example exercise only standard speeds(100Kbps and 400Kbps) for I2C clock. High speed(1 Mbps and 3.3 Mbps) I2C clocks are supported in driverlib, but not exercised in this example.
  2. Populating the jumpers J2 and J3 will turn the LED D5 and D6 on and hence will not be available for use.