Example Summary

Demonstrates how to use SPI driver in controller mode to communicate with another SimpleLink device. To run this example successfully, another SimpleLink device running the spiperipheral example is required.

Peripherals & Pin Assignments

When this project is built, the SysConfig tool will generate the TI-Driver configurations into the ti_drivers_config.c and ti_drivers_config.h files. Information on pins and resources used is present in both generated files. Additionally, the System Configuration file (*.syscfg) present in the project may be opened with SysConfig’s graphical user interface to determine pins and resources used.

BoosterPacks, Board Resources & Jumper Settings

This example requires two LaunchPads.

For board specific jumper settings, resources and BoosterPack modifications, refer to the Board.html file.

If you’re using an IDE such as Code Composer Studio (CCS) or IAR, please refer to Board.html in your project directory for resources used and board-specific jumper settings.

The Board.html can also be found in your SDK installation:

<SDK_INSTALL_DIR>/source/ti/boards/<BOARD>

Before running the example the following pins must be connected between controller and peripheral devices.

SPI Controller LaunchPad SPI Peripheral LaunchPad
CONFIG_SPI_CONTROLLER_CLK CONFIG_SPI_PERIPHERAL_CLK
CONFIG_SPI_CONTROLLER_PICO CONFIG_SPI_PERIPHERAL_PICO
CONFIG_SPI_CONTROLLER_POCI CONFIG_SPI_PERIPHERAL_POCI
CONFIG_SPI_CONTROLLER_CSN CONFIG_SPI_PERIPHERAL_CS
CONFIG_SPI_CONTROLLER_READY CONFIG_SPI_CONTROLLER_READY
CONFIG_SPI_PERIPHERAL_READY CONFIG_SPI_PERIPHERAL_READY

Example Usage

The connection will have the following settings:

    Baud-rate:     115200
    Data bits:          8
    Stop bits:          1
    Parity:          None
    Flow Control:    None

Messages should appear as follows:

    Starting the SPI controller example
    This example requires external wires to be connected to the header pins. Please see the Board.html for details.

    Controller SPI initialized

    Controller received: Hello from peripheral, msg#: 0
    Controller received: Hello from peripheral, msg#: 1
    Controller received: Hello from peripheral, msg#: 2
    Controller received: Hello from peripheral, msg#: 3
    Controller received: Hello from peripheral, msg#: 4
    Controller received: Hello from peripheral, msg#: 5
    Controller received: Hello from peripheral, msg#: 6
    Controller received: Hello from peripheral, msg#: 7
    Controller received: Hello from peripheral, msg#: 8
    Controller received: Hello from peripheral, msg#: 9

    Done

Application Design Details

This application uses a single thread:

controllerThread - creates the controller SPI message, opens CONFIG_SPI_CONTROLLER and waits for the peripheral to be ready for a SPI transfer. When the peripheral is ready it starts the transfer. Once complete, the controller prepares the next transaction and waits for the peripheral once more. A total of MAX_LOOP SPI transactions are performed in this manner.

The controllerThread performs the following actions:

  1. Before performing transfers, we must make sure the spicontroller and spiperipheral applications are synchronized with each other. The controller will set CONFIG_SPI_CONTROLLER_READY to 1 to notify the peripheral it is ready to synchronize. The controller will then wait for the peripheral to set CONFIG_SPI_PERIPHERAL_READY to 1 in acknowledgment.

  2. Opens CONFIG_SPI_CONTROLLER and sets CONFIG_SPI_CONTROLLER_READY to 0. Setting CONFIG_SPI_CONTROLLER_READY will notify the peripheral CONFIG_SPI_CONTROLLER has been opened.

  3. Waits for the peripheral to be ready for the SPI transfer. The peripheral will pull CONFIG_SPI_PERIPHERAL_READY low when ready for a transfer.

  4. Creates a SPI transaction structure and sets txBuffer to Hello from controller, msg# n, where n is the iteration number.

  5. Toggles CONFIG_GPIO_LED_1.

  6. Transfers the message. If the transfer is successful, the message received from the peripheral SPI is printed. Otherwise, an error message is printed.

  7. Sleeps for 3 seconds.

  8. Repeats from step 3 for MAX_LOOP iterations.

  9. Closes the SPI driver object and terminates execution.

FreeRTOS: