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 Example with other methods

Overview

The I2C Example project is a demonstration program that uses the KSDK software. This example provides 4 examples: I2C blocking, non blocking, callback and polling.

Supported Platforms

These Freescale Freedom development platforms and Tower System modules are supported by the I2C example.

System Requirement

Hardware requirements

Toolchain requirements

Software requirements

Getting Started

Hardware settings

This example requires two separate boards. Connect an instance of the I2Cx master to the I2Cx slave. The process is the same as the I2C common instance in the demo project:

Master Board Connects To Slave Board
SDA -> SDA
SCL -> SCL
GND -> GND

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
PTB2/I2C0_SCL J24 Pin 12 -> PTB2/I2C0_SCL J24 Pin 12
PTB3/I2C0_SDA J24 Pin 10 -> PTB3/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
PTE24/I2C0_SCL J2 Pin 20 -> PTE24/I2C0_SCL J2 Pin 20
PTE25/I2C0_SDA J2 Pin 18 -> PTE25/I2C0_SDA J2 Pin 18
GND J2 Pin 14 -> GND J2 Pin 14

FRDM-KL02Z & FRDM-KL03Z:

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

FRDM-KL25Z, TWR-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 J2 Pin 14 -> GND J2 Pin 14

FRDM-KL26Z:

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

FRDM-KL27Z & FRDM-KL43Z & FRDM-KL46Z:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
PTD7/I2C1_SCL (*) J2 Pin 20 -> PTD7/I2C1_SCL (*) J2 Pin 20
PTD6/I2C1_SDA (*) J2 Pin 18 -> PTD6/I2C1_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 REVD and I2C1 Connects To Slave Board
Pin Name Board Location Pin Name Board Location
PTE1/I2C1_SCL J15 Pin 12 -> PTE1/I2C1_SCL J15 Pin 12
PTE0/I2C1_SDA J14 Pin 12 -> PTE0/I2C1_SDA J14 Pin 12
GND J14 Pin 18 -> GND J14 Pin 18

TWR-K21D50M & TWR-K22F120M & TWR_K24F120M & TWR-KV31F120M & TWR-KL43Z48M & TWR-KV31F120M:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
PTE24/I2C0_SCL (*) Primary Elevator A7 -> PTE24/I2C0_SCL (*) Primary Elevator A7
PTE25/I2C0_SDA (*) Primary Elevator A8 -> PTE25/I2C0_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-K60D100M & TWR-K64F120M:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
PTE10/I2C1_SCL Primary Elevator A75 -> PTE10/I2C1_SCL Primary Elevator A75
PTE11/I2C1_SDA Primary Elevator B71 -> PTE11/I2C1_SDA Primary Elevator B71
GND Primary Elevator A6 -> GND Primary Elevator A6

TWR-K65F180M:

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

TWR-KV46F150M:

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

TWR-K21F120M:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
PTC10/I2C1_SCL Primary Elevator B50 -> PTC10/I2C1_SCL Primary Elevator B50
PTC11/I2C1_SDA Primary Elevator B51 -> PTC11/I2C1_SDA Primary Elevator B51
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

Prepare the example

  1. Connect a USB cable between the PC host and the OpenSDA USB port on the board.
  2. Open a serial terminal with these settings:
    • 115200 baud rate
    • 8 data bits
    • No parity
    • One stop bit
    • No flow control
  3. Download the program to the target board.
  4. Either press the reset button on your board or launch the debugger in your IDE to begin running the example.

Run the example

I2C blocking

These instructions are displayed/shown on the terminal window:

On Master board:

==================== I2C MASTER BLOCKING ===================
1. Master sends a frame includes CMD(size of data) and data
2. Master receives data from slave.
3. Compare rxBuff and txBuff to see result.
============================================================
Press any key to start transfer:

Type a character on the keyboard and the master board sends to the slave board and receives back from the slave board.

On Master board:

Master sends 1 bytes:
01
Master Sends/ Receives 1 bytes successfully
Master sends 2 bytes:
01 02
Master Sends/ Receives 2 bytes successfully
Master sends 3 bytes:
01 02 03
Master Sends/ Receives 3 bytes successfully
Master sends 4 bytes:
01 02 03 04
Master Sends/ Receives 4 bytes successfully
...

On Slave board:

==================== I2C SLAVE BLOCKING ===================
Slave is running ...
Slave received:
01
Slave received:
01 02
Slave received:
01 02 03
Slave received:
01 02 03 04
Slave received:
01 02 03 04 05
...

I2C non-blocking

These instructions are displayed/shown on the terminal window same as above.

I2C callback

These instructions are displayed/shown on the terminal window same as above.

I2C polling

These instructions are displayed/shown on the terminal window same as above.