Class: SPI

spi~SPI(options)

A SPI master interface

Constructor

new SPI(options)

Creates a SPI master interface. Destroy explicitly with destroy() when the interface is no longer in use.
Parameters:
Name Type Description
options Object The options
Properties
Name Type Attributes Default Description
mode Number <optional>
0 0: capture data on first edge, the rest state of the clock (between frames) is low / 1: capture data on second edge, the rest state of the clock (between frames) is low / 2: capture data on first edge, the rest state of the clock (between frames) is high / 3: capture data on second edge, the rest state of the clock (between frames) is high
clockHz Number <optional>
500000 speed of link in Hz
pinSCLK Number clock signal pin
pinMISO Number <optional>
master to slave/output pin
pinMOSI Number <optional>
slave to master/input pin
Source:

Methods

addCS(pinCS) → {SPI}

Acquires the given pin to use it as chip select pin during transfers. Sets the pin level to high. When transfering data with this chip select pin the pin level goes low during transfer.
Parameters:
Name Type Description
pinCS Number chip select pin
Source:
Returns:
interface itself, to chain call other methods
Type
SPI

destroy()

Frees all resources of the interface, allowing the program to use the pins differently or construct a new interface with other parameters.
Source:

flush(callback)

Calls the callback as soon as the last transfer is completed.
Parameters:
Name Type Description
callback SPITransferCallback called when the last transfer is completed
Source:

ref() → {SPI}

Tells the interface to keep the program running when a transfer is taking place. This is the default.
Source:
Returns:
interface itself, to chain call other methods
Type
SPI

removeCS(pinCS) → {SPI}

Allows the program to use the given pin differently. Sets the pin level to input.
Parameters:
Name Type Description
pinCS Number chip select pin
Source:
Returns:
interface itself, to chain call other methods
Type
SPI

transfer(pinCSopt, data, callbackopt)

Transfers data to and from the slave.
Parameters:
Name Type Attributes Description
pinCS Number <optional>
chip select pin
data Buffer data to send to slave
callback SPITransferCallback <optional>
called when the transfer is completed
Source:

unref() → {SPI}

Tells the interface to not keep the program running when a transfer is taking place, but there is nothing else to do.
Source:
Returns:
interface itself, to chain call other methods
Type
SPI