nRF51 SDK - S110 SoftDevice
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
SPI master Loopback Example

The SPI master Loopback Example is for demonstrating the SPI Master using a Loopback for verification. There are two ways to make the loopback complete: Either connect and configure a slave to transmit the received bytes or wire the MOSI and MISO pins of the SPI master together. Both SPI_MASTER_0 and SPI_MASTER_1 are tested in this example. It uses the hardware delivered in the nRF51822 Development Kit.

TX_RX_MSG_LENGTH number of bytes are transmitted through the master and the received bytes are verified to be the same as transmitted. If there is an error, the GPIO pin for the relevant SPI module is set high to show the error

  • ERROR_PIN_SPI0 (Pin 8, P1.0).
  • ERROR_PIN_SPI1 (Pin 9, P1.1).

If there is error from both modules, both pins go high and the application loops infinitely.

The application is started with configuring GPIO. Both SPI_MASTER_0 and SPI_MASTER_1 are tested, first with shifting lsb first, then by shifting msb first. If there is an error, the LED will be turned on.

Setup

Instructions on how to set up the nRFgo Motherboard: nRFgo Motherboard Setup (nRF6310).

If a slave is configured to transmit the received bytes:
Configuration for SPI_MASTER_0:

  • SCK0 (Pin 25, P3.1).
  • MOSI0 (Pin 20, P2.4).
  • MISO0 (Pin 22, P2.6).
  • SS0 (Pin 24, P3.0).

Configuration for SPI_MASTER_1:

  • SCK1 (Pin 29, P3.5).
  • MOSI1 (Pin 21, P2.5).
  • MISO1 (Pin 23, P2.7).
  • SS1 (Pin 28, P3.4).

If MOSI and MISO are connected together:

  • MOSI0 (Pin 20, P2.4) should be connected to MISO0 (Pin 22, P2.6).
  • MOSI1 (Pin 21, P2.5) should be connected to MISO1 (Pin 23, P2.7).

LED assignments:

  • LED 0 is used to show if SPI_MASTER_0 had an error.
  • LED 1 is used to show if SPI_MASTER_1 had an error.

Testing

The SPI master Loopback Example Application can be tested as follows:

  1. Compile and program the application.
  2. Observe that no LEDs are lit on the board.
  3. If LED 0 is lit, SPI_MASTER_0 had an error.
  4. If LED 1 is lit, SPI_MASTER_1 had an error.