Skip to main content

Arduino Software SPI User Guide

Similarly to I2C and Serial communications, SPI can be virtualized using software to overcome the physical limitations. Here provides an example of using software SPI with Arduino.

What is SPI

Serial Peripheral Interface (SPI) is a synchronous serial data protocol used by microcontrollers for communicating with one or more peripheral devices quickly over short distances. It can also be used for communication between two microcontrollers.

Software SPI Example

  1. Visit the SoftSPI repositories and download the entire repo to your local drive.

  2. Now, the SoftSPI library can be installed to the Arduino IDE. Open the Arduino IDE, and click sketch -> Include Library -> Add .ZIP Library, and choose the SoftSPI file that you've have just downloaded.

InstallLibrary

#include <SPI.h>
#include <SoftSPI.h>

// Create a new SPI port with:
// Pin 2 = MOSI,
// Pin 3 = MISO,
// Pin 4 = SCK
SoftSPI mySPI(2, 3, 4);

void setup() {
mySPI.begin();
Serial.begin(9600);
}

void loop() {
static uint8_t v = 0;

Serial.print("Sending value: ");
Serial.print(v, HEX);
uint8_t in = mySPI.transfer(v);
Serial.print(" Got value: ");
Serial.print(in, HEX);
Serial.println(v == in ? " PASS" : " FAIL");
delay(1000);
v++;
}

Tech Support & Product Discussion

Thank you for choosing our products! We are here to provide you with different support to ensure that your experience with our products is as smooth as possible. We offer several communication channels to cater to different preferences and needs.

Loading Comments...