SPIOpen (Open SPI Communication)

The SPIOpen instruction sets up the datalogger to perform SPI communication as an SPI controller.

NOTE: Campbell Scientific documentation has been updated to replace legacy industry terms with modern terminology. Controller-peripheral are now used to describe SPI communications. The SPI controller initiates communications and makes requests of peripheral device(s). Peripheral devices process requests and return an appropriate response See https://www.oshwa.org/a-resolution-to-redefine-spi-signal-names for more information.

Syntax

SPIOpen ( BeginPort, BitRate, Option )

Remarks

Note that a prior understanding of the operation and details of the SPI protocol is assumed.

SPIOpen must be declared prior to using SPIRead or SPIWrite.

Serial Peripheral Interface (SPI) protocol is a clocked synchronous interface that is used for short-distance communication, generally between embedded devices. When SPIOpen() is executed, three terminal blocks are dedicated to function as the SPI clock signal (SCK), Controller-Out, Peripheral-In signal (COPI), and Controller-In, Peripheral-Out signal (CIPO).

Parameters

BeginPort

The beginning port used for the three signals for SPI communications. The first port is the SPI clock signal. The next higher port from the clock port is the Controller Out Peripheral In (COPI) signal, and the next higher port is Controller In Peripheral Out (CIPO). BeginPort can be C1, U1, U5, or U9. If an additional chip select (CS) signal is required, it can be managed with PortSet instructions surrounding the SPI accesses.

Type: Constant

BitRate

The synchronous clock rate in hertz for the clock signal.

Type: Constant

Option

A bit field that is used to configure the operation of the SPI interface. The bits are defined as:

Field Description

7 Clock Phase (CPHA)

0 = Data is changed on the first CLK edge and captured on the following edge.
1 = Data is captured on the first CLK edge and changed on the following edge.

6 Clock Polarity (CPOL)

0 = The inactive state is low; 1 = The inactive state is high.

5 Data Order

0 = LSB first; 1 = MSB first

4 Byte length

0 = 8 bit and 1 =7 bit

For example: Option field of &H60 Phase=0, Polarity=1, Data=1 and Length=0

Or Option field of &H30 Phase=0, Polarity=0, Data=1 and Length=1

The Diagram below demonstrates different SPI interface configurations and may be used to match the configuration needed for your specific sensor:

Source: https://commons.wikimedia.org/wiki/File:SPI_timing_diagram.svg

Type: Constant