SPI - Serial Peripheral Interface

The Serial Peripheral Interface is a Serial Bus for peripherals that uses Clock, Data In, and Data Out (and often a Chip Select pin).

See SPI Class in the reference

Hardware SPI

On most boards there are hardware SPI peripherals. Check out the pin diagram on the reference page for your board and look for pins marked with an SPI tag.

You can use it as follows.

// set up SPI
SPI1.setup({mosi:B5, miso:B4, sck:B3});

// write data without a response
SPI1.write([1,2,3,4])

// write data with a response
var d = SPI1.send([1,2,3,4]);

See the reference for SPI.setup for more information on the arguments that can be passed in.

Software SPI

If you don't have access to your board's pins, you can also emulate SPI in software:

// set up SPI
var spi = new SPI();
spi.setup({mosi:B5, miso:B4, sck:B3});

// write data without a response
spi.write([1,2,3,4])

// write data with a response
var d = spi.send([1,2,3,4]);

Speed (baud rate)

Pretty much all SPI devices are guaranteed to support 100kBits/sec transfer speed, so that is the default in Espruino. However you can specify higher speeds with bitrate in SPI.setup if your device supports it, eg:

SPI1.setup({ mosi:B5, miso:B4, sck:B3, baud: 400000 });

Note: baud rate is ignored for software SPI - it will always send as fast as possible.

Using SPI

ADNS5050 Optical Mouse SensorADNS5050 Optical Mouse SensorILI9163 LCD controllerILI9163 LCD controllerILI9341 LCD controllerILI9341 LCD controllerMAX7219 7 segment display driverMAX7219 7 segment display driverPCD8544 LCD driver (Nokia 5110)PCD8544 LCD driver (Nokia 5110)SH1106 OLED driverSH1106 OLED driverSSD1306 OLED driverSSD1306 OLED driverSSD1351 OLED display driverSSD1351 OLED display driverSSD1606 e-Paper display driverSSD1606 e-Paper display driverSharp Memory LCDSharp Memory LCDADS7843 TouchscreenADS7843 TouchscreenHopeRF RFM69 Wireless ModuleHopeRF RFM69 Wireless ModuleLIS2DH12 AccelerometerLIS2DH12 AccelerometerLIS302DL AccelerometerLIS302DL AccelerometerMCP23xxx I2C and SPI port expandersMCP23xxx I2C and SPI port expandersMCP4xxx I2C and SPI digital potentiometersMCP4xxx I2C and SPI digital potentiometersMCP4xxx0 SPI digital potentiometersMCP4xxx0 SPI digital potentiometersMFRC522 NFC/RFID moduleMFRC522 NFC/RFID moduleST7565/ST7567 128x64 Monochrome LCD driverST7565/ST7567 128x64 Monochrome LCD driverSX1276/77/78/79 LoRa ModulesSX1276/77/78/79 LoRa ModulesTouchscreenTouchscreen

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.