Kinetis SDK v.1.2 Demo Applications User's Guide  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
I2C Communication Demo

This demo application demonstrates the I2C demo.

Overview

The I2C communication application demonstrates I2C data communication between two boards. It also features low power wakeup of the slave board by using I2C address matching. First, the I2C slave board enters the low power wait mode. An LED on the I2C slave board is on to indicate that the MCU is in sleep mode and no code is running. Then, the I2C slave board is woken up by the I2C address matching interrupt when the I2C master boards sends the proper address. The LED on the I2C slave board is toggled during the data communication. After power on, the I2C master starts reading data from the I2C slave data buffer. The I2C slave has "sub" addresses to access a specific byte of data on the slave board. The master prints this data out via the serial terminal. The master can then modify the data at a specific "sub" address on the slave board. When the data is received, the I2C slave changes the content at that requested "sub" address. This change is reflected when the master reads the slave data buffer again.

Supported Platforms

These Freescale Freedom development platforms and Tower System modules are supported by the KSDK I2C Communication demo.

System Requirement

Hardware requirements

Toolchain requirements

Software requirements

Getting Started

Hardware configuration

This demo requires two separate boards. Make these connections between the two boards by using external wires:

FRDM-K22F:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
I2C0_SCL J24 Pin 12 -> I2C0_SCL J24 Pin 12
I2C0_SDA J24 Pin 10 -> I2C0_SDA J24 Pin 10
GND J2 Pin 14 -> GND J2 Pin 14

FRDM-K64F:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
I2C0_SCL J2 Pin 20 -> I2C0_SCL J2 Pin 20
I2C0_SDA J2 Pin 18 -> I2C0_SDA J2 Pin 18
GND J2 Pin 14 -> GND J2 Pin 14

FRDM-KL02Z:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
I2C0_SCL J7 Pin 10 -> I2C0_SCL J7 Pin 10
I2C0_SDA J7 Pin 9 -> I2C0_SDA J7 Pin 9
GND J7 Pin 7 -> GND J7 Pin 7

FRDM-KL03Z:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
I2C0_SCL J2 Pin 10 -> I2C0_SCL J2 Pin 10
I2C0_SDA J2 Pin 9 -> I2C0_SDA J2 Pin 9
GND J2 Pin 7 -> GND J2 Pin 7

FRDM-KL25Z:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
I2C1_SCL J10 Pin 12 -> I2C1_SCL J10 Pin 12
I2C1_SDA J10 Pin 10 -> I2C1_SDA J10 Pin 10
GND J9 Pin 14 -> GND J9 Pin 14

FRDM-KL26Z:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
I2C0_SCL J2 Pin 20 -> I2C0_SCL J2 Pin 20
I2C0_SDA J2 Pin 18 -> I2C0_SDA J2 Pin 18
GND J2 Pin 14 -> GND J2 Pin 14

FRDM-KL27Z:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
I2C1_SCL J2 Pin 20 -> I2C1_SCL J2 Pin 20
I2C1_SDA J2 Pin 18 -> I2C1_SDA J2 Pin 18
GND J2 Pin 14 -> GND J2 Pin 14

FRDM-KL43Z, FRDM-KL46Z:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
I2C0_SCL J2 Pin 20 -> I2C0_SCL J2 Pin 20
I2C0_SDA J2 Pin 18 -> I2C0_SDA J2 Pin 18
GND J2 Pin 14 -> GND J2 Pin 14

FRDM-KW24:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
I2C0_SCL J2 Pin 20 -> I2C0_SCL J2 Pin 20
I2C0_SDA J2 Pin 18 -> I2C0_SDA J2 Pin 18
GND J2 Pin 14 -> GND J2 Pin 14

MRB-KW01:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
I2C0_SCL J15 Pin 12 -> I2C0_SCL J15 Pin 12
I2C0_SDA J14 Pin 8 -> I2C0_SDA J14 Pin 8
GND J14 Pin 18 -> GND J14 Pin 18

TWR-K21D50M:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
I2C1_SCL Primary Elevator A7 -> I2C1_SCL Primary Elevator A7
I2C1_SDA Primary Elevator A8 -> I2C1_SDA Primary Elevator A8
GND Primary Elevator A6 -> GND Primary Elevator A6

TWR-K22F120M, TWR-K24F120M, TWR-K60D100M & TWR-KV31F120M:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
I2C0_SCL Primary Elevator A7 -> I2C0_SCL Primary Elevator A7
I2C0_SDA Primary Elevator A8 -> I2C0_SDA Primary Elevator A8
GND Primary Elevator A6 -> GND Primary Elevator A6

TWR-K64F120M:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
I2C1_SCL Primary Elevator A75 -> I2C1_SCL Primary Elevator A75
I2C1_SDA Primary Elevator A60 -> PTC11/I2C1_SDA Primary Elevator A60
GND Primary Elevator A65 -> GND Primary Elevator A65

TWR-KL43Z48M:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
I2C1_SCL Primary Elevator A7 -> I2C1_SCL Primary Elevator A7
I2C1_SDA Primary Elevator A8 -> I2C1_SDA Primary Elevator A8
GND Primary Elevator A6 -> GND Primary Elevator A6

TWR-KV10Z32:

Note: Board is required to short J7 pin 2-3 and J9 pin 2-3 to enable pull up resistors on SDA0, SCL0.

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
I2C0_SCL Primary Elevator A7 -> I2C0_SCL Primary Elevator A7
I2C0_SDA Primary Elevator A8 -> I2C0_SDA Primary Elevator A8
GND Primary Elevator A6 -> GND Primary Elevator A6

TWR-K65F180M, TWR-KV46F150M:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
I2C0_SCL Primary Elevator - Pin A7 -> I2C0_SCL Primary Elevator - Pin A7
I2C0_SDA Primary Elevator - Pin A8 -> I2C0_SDA Primary Elevator - Pin A8
GND Primary Elevator A65 -> GND Primary Elevator A65

TWR-KW24D512:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
I2C0_SCL Primary Elevator A7 -> I2C0_SCL Primary Elevator A7
I2C0_SDA Primary Elevator A8 -> I2C0_SDA Primary Elevator A8
GND Primary Elevator A81 -> GND Primary Elevator A81

TWR-K21F120M:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
I2C1_SCL Primary Elevator B50 -> I2C1_SCL Primary Elevator B50
I2C1_SDA Primary Elevator B51 -> I2C1_SDA Primary Elevator B51
GND Primary Elevator A65 -> GND Primary Elevator A65

Terminal configuration

Configure the PC host serial console as shown:

Run the demo

  1. Connect the I2C slave board to the master board using the connections listed above.
  2. Power on the I2C slave board.
  3. Download and run the i2c_comm_slave project to the I2C slave board.
  4. The terminal of the I2C slave board prints out a "====== I2C Slave ======" message.
  5. Power on the I2C master board.
  6. Download and run the i2c_comm_mstr project to the I2C master board.
  7. The terminal of the I2C master board prints out a "====== I2C Master ======" message and the data received from the I2C slave.
  8. The I2C slave project creates some "sub" addresses to access a specific byte of data on the slave board. The master reads all these "sub" addresses and prints out the data.

    Slave Sub Address Character
    [0]I
    [1]2
    [2]C
    [3]-
    [4]C
    [5]O
    [6]M
    [7]M
  9. To change the I2C slave sub address content, input a new character in the I2C master command line:
    Input slave sub address and the new character.
    Slave Sub Address: 5
    Input New Character: F
  10. The master then displays the updated content on the terminal output.
    Slave Sub Address Character
    [0]I
    [1]2
    [2]C
    [3]-
    [4]C
    [5]F
    [6]M
    [7]M