Link Search Menu Expand Document

MCHP

SERCOM SPI Slave read write

This example application demonstrates how to use the SERCOM SPI peripheral in slave mode

Description

This example uses the SERCOM SPI peripheral library in slave mode and allows reading and writing data from/to its internal buffer by a SPI master.

The SPI master writes data by sending a write command followed by two bytes of memory address followed by the data to be written.

< WR_CMD > < ADDR_MSB > < ADDR_LSB > < DATA0 > … < DATA n >

After sending the write command, the SPI master polls the busy status of SPI slave by reading the busy status byte from SPI slave.

Once the SPI slave is ready, the SPI master reads the data by sending read command followed by two bytes of memory address and the number of bytes to read.

< RD_CMD > < ADDR_MSB > < ADDR_LSB > < NUM_BYTES >

The SPI slave responds by sending the data at the requested memory address. The SPI master compares the sent data with the received data and repeats the test if it matches.

Downloading and building the application

To download or clone this application from Github, go to the top level of the repository and click

clone

Path of the application within the repository is apps/sercom/spi/slave/spi_write_read/firmware .

To build the application, refer to the following table and open the project using its IDE.

Project Name Description
sam_da1_xpro.X MPLABX project for SAM DA1 Xplained Pro Evaluation Kit
   

Setting up the hardware

The following table shows the target hardware for the application projects.

Project Name Board
sam_da1_xpro.X SAM DA1 Xplained Pro Evaluation Kit
   

Setting up SAM DA1 Xplained Pro Evaluation Kit

  • To run this demo two SAM DA1 Xplained Pro Evaluation Kit are required. One will be progammed as SPI master and other will be programmed as SPI slave.
  • Connect Pin 15, 16, 17, 18 on EXT2 of SPI slave to Pin 15, 16, 17, 18 on EXT2 of SPI master
    • Pin 15 - SPI Chip Select
    • Pin 16 - MOSI
    • Pin 17 - MISO
    • Pin 18 - SCK
  • Connect the Debug USB port on the board to the computer using a micro USB cable

Running the Application

  1. Build and Program the SPI master application project using its IDE. Path of the SPI Master application within the repository is apps/sercom/spi/master/spi_write_read_test_app/firmware
  2. Build and Program the SPI slave application project using its IDE
  3. On the SPI master board, press switch to start reading and writing data
  4. LED on SPI master board indicates the success or failure:
    • LED is turned ON when the data read from the SPI slave matches with the data written
    • LED is turned OFF when the data read from the SPI slave does not match with the data written

Following table provides the Switch and LED name:

Board Switch Name LED Name
SAM DA1 Xplained Pro Evaluation Kit SW0 LED0
     


Copyright © 2020 Microchip Technology.