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.
- 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>/demo_apps/i2c_comm/<mode>/<toolchain>. Where <mode> is either master or slave.
- Library dependencies: ksdk_platform_lib
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:
- 115200 baud rate
- 8 data bits
- No parity
- One stop bit
- No flow control
Run the demo
-
Connect the I2C slave board to the master board using the connections listed above.
-
Power on the I2C slave board.
-
Download and run the i2c_comm_slave project to the I2C slave board.
-
The terminal of the I2C slave board prints out a "====== I2C Slave ======" message.
-
Power on the I2C master board.
-
Download and run the i2c_comm_mstr project to the I2C master board.
-
The terminal of the I2C master board prints out a "====== I2C Master ======" message and the data received from the I2C slave.
-
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 |
-
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
-
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 |