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.
- I2C master sends and receives the array to/from the I2C slave and compares whether the two buffers are the same
- I2C slave sends the buffer received from the master then echoes back to the master
- First run the master and then run the slave
Supported Platforms
These Freescale Freedom development platforms and Tower System modules are supported by the I2C example.
- FRDM-K22F
- FRDM-K64F
- FRDM-KL02Z
- FRDM-KL03Z
- FRDM-KL25Z
- FRDM-KL26Z
- FRDM-KL27Z
- FRDM-KL43Z
- FRDM-KL46Z
- FRDM-KW24
- MRB-KW01
- TWR-K21D50M
- TWR-K21F120M
- TWR-K22F120M
- TWR-K24F120M
- TWR-K60D100M
- TWR-K64F120M
- TWR-K65F180M
- TWR-KL43Z48M
- TWR-KV10Z32
- TWR-KV31F120M
- TWR-KV46F150M
- TWR-KW24D512
System Requirement
Hardware requirements
- J-Link ARM
- P&E Micro Multi-link universal
- Mini/micro USB cable
- USB A to micro AB cable
- Hardware (tower/base board, ...) for specific device
- Personal Computer
Toolchain requirements
- IAR embedded Workbench version 7.30.4
- ARM GCC 4.8.3 2014q3
- Keil MDK 5.13
- Kinetis Design Studio IDE v.2.5.0
- Atollic TrueSTUDIO for ARM win32 v5.2.1
Software requirements
- The project files are in: <SDK_Install>/examples/<board>/driver_examples/i2c/<use_case>/<toolchain>.
- Library dependencies: ksdk_platform_lib
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
- Connect a USB cable between the PC host and the OpenSDA USB port on the board.
- Open a serial terminal with these settings:
- 115200 baud rate
- 8 data bits
- No parity
- One stop bit
- No flow control
- Download the program to the target board.
- 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.
============================================================
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.