nRF51 SDK
 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 SPI0 and SPI1 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.
  • ERROR_PIN_SPI1.

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

The application is started with configuring GPIO. Both SPI0 and SPI1 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:

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

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 SPI0 had an error.
  • LED 1 is used to show if SPI1 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, SPI0 had an error.
  4. If LED 1 is lit, SPI1 had an error.