Skip to main content
Skip table of contents

13.4 SPI [T-Series Datasheet]

SPI Overview

SPI (serial peripheral interface) is a four-wire synchronous serial protocol. SPI is considered an advanced topic. A good knowledge of the protocol is recommended. Troubleshooting may require a logic analyzer or oscilloscope.

T-series SPI Support

T-Series devices support Serial Peripheral Interface (SPI) communication as the master only. Four digital IO lines are used: MISO (data line; Master In Slave Out), MOSI (data line; Master Out Slave In), CLK (clock), and CS (chip select).

Lua scripting is often convenient for serial applications. For example, a script can run the serial communication at a specified interval, and put the results in USER_RAM registers. The host software can read from the USER_RAM registers when convenient. This puts the complications of serial communication in a script running on the T-series device. The Lua examples contain several serial communication examples.

SPI is not an alternative to the USB connection. Rather, the host application will write/read data to/from the T-series device, and the T-series device communicates with some other device using the serial protocol.

How-To

Device Control Basics

  • All T-series device features are controlled by reading and writing Modbus TCP registers via Modbus TCP (either directly or through our LJM library).
  • We have register descriptions throughout documentation detailing relevant register names, starting addresses, types, and access permissions (read/write).
  • See Section 3.0 Communication for other detailed communication information.

Process

Running a SPI operation on a T-series device requires:

  1. Initial configuration.
  2. Send load data to the slave device.
  3. Execute the SPI operation.
  4. Read the data that was read from the slave device.

Initial configuration.

Several registers need to be written to configure the T-series device.

DIO lines need to be selected to act as MISO, MOSI, CLK, and CS:

The SPI mode controls which edge of clock signals value data, and whether the clock will idle high or low:

Set the clock speed with SPI_SPEED_THROTTLE:

Starting with a low clock speed and increasing the speed after everything is working is usually a good idea.

The following table lists approximate clock rates measured for various values of SPI_SPEED_THROTTLE with T7 firmware 1.0150:

Throttle ValueClock Speed [kHz]
0780
65530380
65500100
6510010
611001
210000.1
10.067

Lastly, set SPI_OPTIONS:

Setting SPI_OPTIONS is normally not needed, but can help with compatibility in the following situations:

  • If the hardware setup does not require a CS line.
  • If the hardware setup requires special digital IO configuration.
  • If data needs to be transmitted LSB first.
  • If the number of bits to be transferred is not an even multiple of eight.

Send load data to the slave device.

SPI is full duplex. That means that data is sent in both directions at the same time. The number of bytes read from the slave must always equal the number of bytes written to the slave and the maximum transfer size is 100 bytes. To read data from a slave device without sending data to it, load dummy data into SPI_DATA_TX.

Execute the SPI operation.

Read the data that was read from the slave device.

Common Issues

Timeouts

T-Series devices have an internal watchdog that will timeout, and cause the device to reboot, if a single SPI transaction lasts longer than 250 ms. Stay safely above the following measured minimum values where device did not reboot for different numbers of bytes:

# BytesThrottle ValueClock Rate [Hz]
1167
2490073
323900106
433900140
1052600342
1657400544
32615001

Noise Immunity

The clock input on the slave device can be vulnerable to noise. The clock input will notice quick edges caused by noise. If you suspect this to be a problem, add a capacitor close to the clock input of the slave. Suggested value is equal to or less than:

1 / (2 * pi * f * R)

...where f is the SPI frequency and R is the source impedance—which is dominated in this case by the DIO (use 550 ohms for FIO and 180 ohms for EIO).

Example

The following demonstrates a simple loop-back test. Connect a jumper between DIO2 and DIO3. Data will be sent out DIO3 and read from DIO2.

SPI_CS_DIONUM = 0           // Use DIO0 as chip select.
SPI_CLK_DIONUM = 1          // Use DIO1 as Clock
SPI_MISO_DIONUM = 2         // Use DIO2 as MISO
SPI_MOSI_DIONUM = 3         // Use DIO3 as MOSI
SPI_MODE = 0                // Select mode zero.
SPI_SPEED_THROTTLE = 65500  // Set clock speed to ~100 kHz.
SPI_OPTIONS = 0             // No special operation
SPI_NUM_BYTES = 1           // Transfer one byte.
SPI_DATA_TX = 0x55          // Load a test data byte. eWriteNameByteArray is the easiest way to write the outgoing SPI data.
SPI_GO = 1                  // Initiate the transfer

At this point the T-series device T7 will run the SPI transaction. If no errors are returned, the received data can be read.

Read a test data byte. eReadNameByteArray is the easiest way to read the received SPI data.

Because of the loop-back, the data read from SPI_DATA_RX will match the data written to SPI_DATA_TX.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.