Overview
The FlexIO SPI example application demonstrates the FlexIO simulated SPI driver working with different methods. The FlexIO SPI example shows the transmit/receive between the FlexIO-simulated SPI and SPI1 using these methods:
master
- Using interrupts
- Using the DMA
slave
- Using the interrupts
- Using the DMA
Supported Platforms
This Tower System module is supported by the FlexIO SPI example:
- TWR-KL43Z48M
- FRDM-KL27Z48M
System Requirement
Hardware requirements
- J-Link ARM
- PE Micro Multi-link universal
- Mini/micro USB cable
- USB A to micro AB cable
- 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
- Atollic TrueSTUDIO for ARM win32 v5.2.1
Software requirements
- The project files are in: <SDK_Install>/examples/<board>/driver_examples/flexio/spi/<mode>/<toolchain>.
- Library dependencies: ksdk_platform_lib
Getting Started
Hardware settings
This example requires connecting FlexIO pins with the SPI1 pins. Connect FlexIO pins to the SPI1 pins. Note that the default uses the FlexIO pin0~pin3:
FlexIO Pins | Connects To | SPI1 Pins |
FlexIO Pin0 | -> | SPI1 MOSI/MISO |
FlexIO Pin1 | -> | SPI1 MISO/MOSI |
FlexIO Pin2 | -> | SPI1 SCK |
FlexIO Pin3 | -> | SPI1 CSn |
Make these connections between the FlexIO Pins and the SPI1 pins by using external wires:
master example
FlexIO Pins | Connects To | SPI1 Pins |
Pin Name | Board Location | | Pin Name | Board Location |
PTD0/FLEXIO_PIN0 | Primary Elevator B46 | -> | SPI1 MOSI | Primary Elevator B10 |
PTD1/FLEXIO_PIN1 | Primary Elevator B48 | -> | SPI1 MISO | Primary Elevator B11 |
PTD2/FLEXIO_PIN2 | Primary Elevator B45 | -> | SPI1 SCK | Primary Elevator B7 |
PTD3/FLEXIO_PIN3 | Primary Elevator B44 | -> | SPI1 CSn | Primary Elevator B9 |
FRDM-KL27Z48M
FlexIO Pins | Connects To | SPI1 Pins |
Pin Name | Board Location | | Pin Name | Board Location |
PTD0/FLEXIO_PIN0 | J1-1 | -> | SPI1 MOSI | J2-18 |
PTD1/FLEXIO_PIN1 | J1-3 | -> | SPI1 MISO | J2-20 |
PTD2/FLEXIO_PIN2 | J1-5 | -> | SPI1 SCK | J1-11 |
PTD3/FLEXIO_PIN3 | J1-7 | -> | SPI1 CSn | J1-9 |
slave example
FlexIO Pins | Connects To | SPI1 Pins |
Pin Name | Board Location | | Pin Name | Board Location |
PTD0/FLEXIO_PIN0 | Primary Elevator B46 | -> | SPI1 MISO | Primary Elevator B11 |
PTD4/FLEXIO_PIN1 | Primary Elevator B48 | -> | SPI1 MOSI | Primary Elevator B10 |
PTD2/FLEXIO_PIN2 | Primary Elevator B45 | -> | SPI1 SCK | Primary Elevator B7 |
PTD4/FLEXIO_PIN3 | Primary Elevator B44 | -> | SPI1 CSn | Primary Elevator B9 |
FRDM-KL27Z48M
FlexIO Pins | Connects To | SPI1 Pins |
Pin Name | Board Location | | Pin Name | Board Location |
PTD0/FLEXIO_PIN0 | J1-1 | -> | SPI1 MOSI | J2-20 |
PTD1/FLEXIO_PIN1 | J1-3 | -> | SPI1 MISO | J2-18 |
PTD2/FLEXIO_PIN2 | J1-5 | -> | SPI1 SCK | J1-11 |
PTD3/FLEXIO_PIN3 | J1-7 | -> | SPI1 CSn | J1-9 |
Prepare the example
- Connect a USB cable between the PC host and the OpenSDA USB port on the board.
- For TWR-KL43Z48M, insert TWR board into TWR-ELEV.
- 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
master example
These instructions are displayed/shown on the terminal window:
++++++++++++++++ FLEXIO SPI Send/Receive Example Start +++++++++++++++++
1. FlexIO-simulated SPI
master starts transfer with the masterWriteBuff and masterReadBuff.
2. SPI1 acts as
slave also transfer with the slaveWriteBuff and slaveReadBuff.
3. Compare the masterWriteBuff and the slaveReadBuff and the slaveWriteBuff and the masterReadBuff to see results.
============================================================
Press any key to start the transfer:
Type a character on the keyboard and the FlexIO-simulated SPI master starts the transfer with the SPI1 slave, compares the masterWriteBuff and slaveReadBuff, the slaveWriteBuff and the masterReadBuff to check whether the transfer is successful.
FlexIO simulated SPI
master to SPI
slave bidirectional transfer succeed!!
FlexIO simulated SPI
master to SPI
slave transfer DMA bidirectional transfer succeed!!
FlexIO simulated SPI
master to SPI
slave bidirectional transfer succeed!!
FlexIO simulated SPI
master to SPI
slave transfer DMA bidirectional transfer succeed!!
FlexIO simulated SPI
master to SPI
slave bidirectional transfer succeed!!
FlexIO simulated SPI
master to SPI
slave transfer DMA bidirectional transfer succeed!!
FlexIO simulated SPI
master to SPI
slave bidirectional transfer succeed!!
...
slave example
These instructions are displayed/shown on the terminal window:
++++++++++++++++ FLEXIO SPI Send/Receive Example Start +++++++++++++++++
1. SPI1 acts as
master starts transfer with masterWriteBuff and masterReadBuff.
2. FlexIO simulated SPI
slave also transfer with slaveWriteBuff and slaveReadBuff.
3. Compare masterWriteBuff and slaveReadBuff, slaveWriteBuff and masterReadBuff to see result.
============================================================
Press any key to start transfer:
Type a character on the keyboard and the SPI1 master starts the transfer with the FlexIO- simulated SPI slave, compares the masterWriteBuff and the slaveReadBuff, the slaveWriteBuff and the masterReadBuff to check whether the transfer is successful.
SPI
master to FlexIO simulated SPI
slave bidirectional transfer succeed!!
SPI
master to FlexIO simulated SPI
slave DMA bidirectional transfer succeed!!
SPI
master to FlexIO simulated SPI
slave bidirectional transfer succeed!!
SPI
master to FlexIO simulated SPI
slave DMA bidirectional transfer succeed!!
SPI
master to FlexIO simulated SPI
slave bidirectional transfer succeed!!
SPI
master to FlexIO simulated SPI
slave DMA bidirectional transfer succeed!!
...