1.24 SPI Host Read Write Test Application

This is a SPI Host test application which is provided to demonstrate communication between SPI host and the corresponding SPI client application available under - apps/spi/slave/spi_write_read/firmware

Description

This example uses the SPI peripheral library in host mode and serves as a test application to demonstrate communication between SPI host and corresponding SPI client application available at apps/spi/slave/spi_write_read/firmware.

The SPI host 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 >

The SPI client asserts the Busy line to indicate to the SPI host that it is busy. Once ready, the SPI client de-asserts the Busy line. Once the SPI client is ready, the SPI host 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 client responds by sending the data at the requested memory address. The SPI host compares the sent data with the received data and repeats the test if it matches.

Downloading and Building the Application

To clone or download this application from Github, go to the main page of this repository and then click Clone button to clone this repository or download as zip file. This content can also be downloaded using content manager by following these instructions.

Path of the application within the repository is apps/spi/master/spi_write_read_test_app/firmware.

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

Project NameDescription
pic32mx470_curiosity.XMPLABX project for Curiosity PIC32MX470 Development Board

Setting Up the Hardware

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

Project NameDescription
pic32mx470_curiosity.XCuriosity PIC32MX470 Development Board

Setting Up Curiosity PIC32MX470 Development Board

  • o run this demo two Curiosity PIC32MX470 Development Board are required. One will be programmed as SPI host and other will be programmed as SPI client.
  • Connect Pin 3, 4, 5, 6 of mikroBUS header J10 on SPI host to Pin 3, 4, 6, 5 respectively of mikroBUS header J10 on SPI client
    • Pin 3 - SPI Chip Select
    • Pin 4 - SCK
    • Pin 5 - SDI
    • Pin 6 - SDO
  • Connect Pin 1 of mikroBUS header J10 on SPI host to Pin 1 of mikroBUS header J10 on SPI client. Pin 1 (RB4) is configured as GPIO and serves as the client busy pin.
  • Connect mini USB cable to the ‘Debug USB’ connector(J3) on the board to the computer
    Note: Ensure that the series resistors on the mikroBUS headers are of value 0 Ohms.

Running the Application

  1. Build and Program the SPI host application project using its IDE
  2. Build and Program the SPI client application project using its IDE. Path of the SPI Client application within the repository is apps/spi/slave/spi_write_read/firmware
  3. On the SPI host board, press switch to start reading and writing data
  4. LED on SPI host board indicates the success or failure:
    • LED is turned ON when the data read from the SPI client matches with the data written
    • LED is turned OFF when the data read from the SPI client does not match with the data written
Following table provides the Switch and LED names:
BoardSwitch NameLED Name
Curiosity PIC32MX470 Development BoardS1LED1