Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
SPI Example

This example uses Serial Peripheral Interface (SPI) of one EK board in slave mode to communicate with another EK board's SPI in master mode.


This package can be used with two SAM evaluation kit boards that support DMAC operation. Please connect the SPI pins from one board to another.

  • SAM EK board(MASTER)–SAM EK board(SLAVE)

This example shows control of the SPI, and how to configure and transfer data with SPI. The user needs to configure the SPI as slave or master mode according to UART inputs.

The code can be roughly broken down as follows:

  • 't' will start SPI transfer test.
    1. Configure SPI as master, and set up SPI clock.
    2. Send 4-byte CMD_TEST to indicate the start of test.
    3. Send several 64-byte blocks, and after transmitting the next block, the content of the last block is returned and checked.
    4. Send CMD_STATUS command and wait for the status reports from slave.
    5. Send CMD_END command to indicate the end of test.
  • Set up SPI clock for master.
  1. Compile the application.
  2. Connect the UART port of the evaluation board to the computer and open it in a terminal.
    • Settings: 115200 bauds, 8 bits, 1 stop bit, no parity, no flow control.
  3. Download the program into the evaluation board and run it.
  4. Upon startup, the application will output the following line on the terminal:
    -- Spi DMA Slave Example --
    -- xxxxxx-xx
    -- Compiled: xxx xx xxxx xx:xx:xx --
  5. The following traces detail operations on the SPI example, displaying success or error messages depending on the results of the commands.