Class: SoftSPI

SoftSPI

Represents a SPI (Serial Peripheral Interface) using user defined pins. So it is a software solution instead of using the hardware SPI. The class implements the SPI protocol (https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus), but currently without a frequency support.

Constructor

new SoftSPI(options)

Creates a new SPI instance for a slave device.
Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Default Description
clock Number Pin for clock (SCLK)
miso Number <optional>
Pin for master input slave output (MISO)
mosi Number <optional>
Pin for master output slave input (MOSI)
client Number <optional>
Pin for client select (CS)
clientSelect Number <optional>
LOW (0) Clients needed polarity for activation
mode Number <optional>
0 SPI mode (0 - 3)
bitOrder Number <optional>
MSB (1) Most Significant Bit (MSB = 1) or Least Significant Bit (LSB = 0)
Source:

Members

(static, constant) LSB

Least Significatn Bit (= 0)
Source:

(static, constant) MSB

Most Significant Bit (= 1)
Source:

bitOrder

Returns the bit order.
Source:

bitOrder

Sets the bit order at transfering data.
Source:

mode

Returns the SPI mode.
Source:

mode

Sets the SPI mode.
Source:

Methods

close() → {SoftSPI}

Closes the connection to the client by closing the pins.
Source:
Returns:
Type
SoftSPI

open() → {SoftSPI}

Opens the connection to the client by setting up the pins.
Source:
Returns:
Type
SoftSPI

read(bytes) → {Array}

Reads the number of bytes from client and supplies them as an array.
Parameters:
Name Type Description
bytes Number Number of bytes to read
Source:
Returns:
Type
Array

transfer(data, readopt, writeopt) → {Array}

Transfers the given data to the client and returns data from the client. The given data can be any data, which is transformable to a byte array. Returns the read data from the client as an array. Each element is one byte. The read data has exactly the same number of bytes like the written data.
Parameters:
Name Type Attributes Default Description
data Any
read Boolean <optional>
true Read data from the client
write Boolean <optional>
true Write data to the client
Source:
Returns:
Type
Array

write(data) → {SoftSPI}

Writes the given data to the client.
Parameters:
Name Type Description
data Any
Source:
Returns:
Type
SoftSPI