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
SPI Example with Other Methods

Overview

The SPI Example project is a demonstration program that uses the KSDK software. This example provides 5 examples SPI board to board with 5 modes: SPI polling, non-blocking, blocking, DMA-blocking, DMA-non blocking and SPI loopback

Supported Platforms

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

System Requirement

Hardware requirements

Toolchain requirements

Software requirements

Getting Started

Hardware settings

This example requires two separate boards. Connect the instance SPI0 master to SPI0 slave:

FRDM-KL02Z:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
MISO J7 pin 5 -> MISO J7 pin 5
MOSI J7 pin 4 -> MOSI J7 pin 4
SCK J7 pin 6 -> SCK J7 pin 6
PCS0 J7 pin 3 -> PCS0 J7 pin 3
GND J7 pin 7 -> GND J7 pin 7

FRDM-KL03Z:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
MISO J2 pin 5 -> MISO J2 pin 5
MOSI J2 pin 4 -> MOSI J2 pin 4
SCK J2 pin 6 -> SCK J2 pin 6
PCS0 J2 pin 3 -> PCS0 J2 pin 3
GND J2 pin 7 -> GND J2 pin 7

FRDM-KL25Z:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
MISO J1 pin 11 -> MISO J1 pin 11
MOSI J1 pin 1 -> MOSI J1 pin 1
SCK J1 pin 9 -> SCK J1 pin 9
PCS0 J1 pin 7 -> PCS0 J1 pin 7
GND J2 pin 14 -> GND J2 pin 14

FRDM-KL26Z:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
MISO J1 pin 9 -> MISO J1 pin 9
MOSI J1 pin 11 -> MOSI J1 pin 11
SCK J4 pin 9 -> SCK J4 pin 9
PCS0 J1 pin 7 -> PCS0 J1 pin 7
GND J2 pin 14 -> GND J2 pin 14

FRDM-KL27Z:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
MISO J2 pin 10 -> MISO J2 pin 10
MOSI J2 pin 8 -> MOSI J2 pin 8
SCK J2 pin 12 -> SCK J2 pin 12
PCS0 J2 pin 6 -> PCS0 J2 pin 6
GND J2 pin 14 -> GND J2 pin 14

FRDM-KL43Z:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
MISO J2 pin 10 -> MISO J2 pin 10
MOSI J2 pin 8 -> MOSI J2 pin 8
SCK J2 pin 12 -> SCK J2 pin 12
PCS0 J2 pin 6 -> PCS0 J2 pin 6
GND J2 pin 14 -> GND J2 pin 14

FRDM-KL46Z:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
MISO J3 pin 3 -> MISO J3 pin 3
MOSI J3 pin 5 -> MOSI J3 pin 5
SCK J3 pin 7 -> SCK J3 pin 7
PCS0 J3 pin 9 -> PCS0 J3 pin 9
GND J3 pin 14 -> GND J3 pin 14

MRB-KW01:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
MISO J15 pin 20 -> MISO J15 pin 20
MOSI J15 pin 19 -> MOSI J15 pin 19
SCK J15 pin 18 -> SCK J15 pin 18
PCS0 J14 pin 16 -> PCS0 J14 pin 16
GND J15 pin 15 -> GND J15 pin 15

TWR-KL43Z48M:

Master Board Connects To Slave Board
Pin Name Board Location Pin Name Board Location
MISO Primary Elevator B44 -> MISO Primary Elevator B44
MOSI Primary Elevator B45 -> MOSI Primary Elevator B45
SCK Primary Elevator B48 -> SCK Primary Elevator B48
PCS0 Primary Elevator B46 -> PCS0 Primary Elevator B46
GND Primary Elevator B2 -> GND Primary Elevator B2

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

SPI blocking Master - Slave

Setup the Slave first. The Slave board has to be powered up first) and then the slave board echoes to the terminal:

SPI board to board blocking example
This example run on instance 0
Be sure master's SPI0 and slave's SPI0 are connected
Slave example is running...
SPI is waiting to receive data

Master sends an array to slave and receives the array back from slave and compares whether the two buffers are the same. The master board prints to the terminal:

SPI board to board blocking example
This example runs on instance 0
Ensure that the master's SPI0 and slave's SPI0 are connected
Baud rate in Hz is: 500000
Master transmit:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
Master receive:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
SPI master blocking transfer succeed!
Press any key to run again

The slave board receives and prints to the terminal:

Slave receive:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
Slave example is running...
SPI is waiting to receive data

SPI non-blocking Master - Slave

Set up the Slave first and then the slave board echoes to the terminal:

SPI board to board non-blocking example
This example run on instance 0
Be sure master's SPI0 and slave's SPI0 are connected
Slave example is running...
SPI is waiting to receive data

Master sends an array to slave and receives the array back from slave and compares whether the two buffers are the same. The master board prints to the terminal:

SPI board to board non-blocking example
This example run on instance 0
Ensure that the master's SPI0 and slave's SPI0 are connected
Baud rate in Hz is: 500000
Master transmit:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
Master receive:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
SPI master blocking transfer succeed!
Press any key to run again

The slave board receives and prints to the terminal:

Slave receive:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
Slave example is running...
SPI is waiting to receive data

SPI EDMA blocking Master - Slave

Set up the Slave first and then the slave board echoes to the terminal:

SPI board to board DMA blocking example
This example run on instance 0
Be sure master's SPI0 and slave's SPI0 are connected
Slave example is running...
SPI is waiting to receive data

Master sends an array to slave and receives the array back from slave and compares whether the two buffers are the same. The master board prints to the terminal:

SPI board to board DMA-blocking example
This example run on instance 0
Ensure that the master's SPI0 and slave's SPI0 are connected
Baud rate in Hz is: 500000
Master transmit:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
Master receive:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
SPI master blocking transfer succeed!
Press any key to run again

The slave board receives and prints to the terminal:

Slave receive:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
Slave example is running...
SPI is waiting to receive data

SPI EDMA non-blocking Master - Slave

Set up the Slave first and then the slave board echoes to the terminal:

SPI board to board DMA non-blocking example
This example run on instance 0
Be sure master's SPI0 and slave's SPI0 are connected
Slave example is running...
SPI is waiting to receive data

Master sends an array to slave and receives the array back from slave and compares whether the two buffers are the same. The master board prints to the terminal:

SPI board to board DMA-non-blocking example
This example run on instance 0
Ensure master's SPI0 and slave's SPI0 are connected
Baud rate in Hz is: 500000
Master transmit:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
Master receive:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
SPI master blocking transfer succeed!
Press any key to run again

The slave board receives and prints to the terminal:

Slave receive:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
Slave example is running...
SPI is waiting to receive data

SPI loopback

These instructions are displayed/shown on the terminal window:

SPI loopback example
This example run on instance 0
Be sure MISO-to-MOSI are connected
Baud rate in Hz is: 500000
Master transmit:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
Master receive:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
SPI master blocking transfer succeed!
Press any key to run again