« Close

Datasheets and User Guides

App Notes

Software & Driver


13.3 SPI

The T7 supports Serial Peripheral Interface (SPI) communication as the master only. SPI is a synchronous serial protocol typically used to communicate with chips that support SPI as slave devices.

Lua scripting is often convenient for serial applications.  For example, you might write a script that does the serial communication to get a new reading from the serial device once per second, and puts that reading in a USER_RAM register.  This puts the complications of serial communication in a script running on the T7 itself, and then the host software can just do a simple read of the USER_RAM register when convenient.  We have many serial examples available for Lua scripting.

This serial link is not an alternative to the USB connection. Rather, the host application will write/read data to/from the T7, and the T7 communicates with some other device using the serial protocol. Using this serial protocol is considered an advanced topic. A good knowledge of the protocol is recommended, and a logic analyzer or oscilloscope might be needed for troubleshooting.

The following demonstrate 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 T7 will run the SPI transaction. If no errors are returned the received data can be read.

SPI_DATA_RX = ? - 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.

Following are approximate clock rates measured for various values of SPI_SPEED_THROTTLE with firmware 1.0150:

0 780 kHz
65530 380 kHz
65500 100 kHz
65100 10 kHz
61100 1 kHz
21000 100 Hz
1 67 Hz

The T7 has in internal watchdog that will timeout, and cause the T7 to reboot, if a single SPI transaction lasts longer than 250ms. Stay safely above the following measured minimum values where device did not reboot for different numbers of bytes:

#Bytes ThrottleValue ClockRateHz
1 1 67 Hz (minimum)
2 4900 73 Hz
3 23900 106 Hz
4 33900 140 Hz
10 52600 342 Hz
16 57400 544 Hz
32 61500 1095 Hz


Noise Immunity:

The particular area of concern for noise is the clock input on the slave device.  This input is typically very fast and will notice quick edges causes by severe noise.  If this is of concern 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).


 Register Listing

SPI Registers
Name Start Address Type Access
SPI_GO 5007 UINT16 W
- Address: 5000
The DIO line for Chip-Select.
  • Data type: UINT16  (type index = 0)
  • Readable and writable
  • Default value: 0
- Address: 5001
The DIO line for Clock.
  • Data type: UINT16  (type index = 0)
  • Readable and writable
  • Default value: 0
- Address: 5002
The DIO line for Master-In-Slave-Out.
  • Data type: UINT16  (type index = 0)
  • Readable and writable
  • Default value: 0
- Address: 5003
The DIO line for Master-Out-Slave-In.
  • Data type: UINT16  (type index = 0)
  • Readable and writable
  • Default value: 0
- Address: 5004
The SPI mode controls the clock idle state and which edge clocks the data. Bit 1 is CPOL and Bit 0 is CPHA, so CPOL/CPHA for different decimal values: 0 = 0/0 = b00, 1 = 0/1 = b01, 2 = 1/0 = b10, 3 = 1/1 = b11. For CPOL and CPHA explanations, see Wikipedia article: https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus.
  • Data type: UINT16  (type index = 0)
  • Readable and writable
  • Default value: 0
- Address: 5005
This value controls the SPI clock frequency. Pass 0-65535. Default=0 corresponds to 65536 internally which results in ~800 kHz. 65500 = ~100 kHz, 65100 = ~10 kHz, 61100 = ~1 kHz, 21000 = ~100 Hz, and 1 = ~67 Hz. Avoid setting too low such that the entire transaction lasts longer than the 250 millisecond timeout of the internal watchdog timer.
  • Data type: UINT16  (type index = 0)
  • Readable and writable
  • Default value: 0
- Address: 5006
Bit 0 is Auto-CS-Disable. When bit 0 is 0, CS is enabled. When bit 0 is 1, CS is disabled. Bit 1: 0 = Set DIO directions before starting the SPI operations, 1 = Do not set DIO directions. Bit 2: 0 = Transmit data MSB first, 1 = LSB first. Bits 4-7: This value sets the number of bits that will be transmitted during the last byte of the SPI operation. Default is 8, valid options are 1-8.
  • Data type: UINT16  (type index = 0)
  • Readable and writable
  • Default value: 0
- Address: 5007
Write 1 to begin the configured SPI transaction.
  • Data type: UINT16  (type index = 0)
  • Write-only
  • Default value: 0
- Address: 5009
The number of bytes to transfer.
  • Data type: UINT16  (type index = 0)
  • Readable and writable
  • Default value: 0
- Address: 5010
Write data here. This register is a buffer.
  • Data type: BYTE  (type index = 99)
  • Write-only
  • Default value: 0
  • This register is a Buffer Register
- Address: 5050
Read data here. This register is a buffer. Underrun behavior - fill with zeros.
  • Data type: BYTE  (type index = 99)
  • Read-only
  • Default value: 0
  • This register is a Buffer Register




Hello, I'm working with an absolute angle encoder and new T7 that communicate using the SPI Protocol (RSS-422). The encoder outputs Data_A, Data_B (e.g., Tx+ Tx-) and accepts  CLK_A, and CLK_B. I'm not sure how this corresponds to the SPI registers above since there are not one but two Tx  and Clock channels required. Can you shed some light on this topic and inform me of the best way to wire this up and what registers to use. I'm admittedly an SPI Noob but any point in the right direction would be much appreciated. Thanks.

Encoder Specs (see pg 29:30) - http://www.zettlex.com/wp-content/uploads/2014/06/1incoder-product-guide...


i have labjack T7 and i want to used it in SPI mode but i cant change clock frequency so please tell me, how i can change clock frequency????

and i download the labview example for SPI from this site but it is not working.

kindly send the labview code for SPI with clock frequency control.

chetan lad


What problem are you having with the example "SPI.vi"?  I just tested it with firmware 1.0150 and it works fine for me.  If I install a jumper from FIO1 to FIO2 then "Data Read" returns whatever I send in "Data Write".

If you want to slow down the SPI clock frequency, just add SPI_SPEED_THROTTLE to the "Config Names" array and add the desired value to the "Config Values" array.  I tried this and found that a value of 20000 drops the clock frequency to 100Hz, which does not agree with what is documented on this page, so we will take a closer look at this and follow up.

The numbers listed in the register definition are off. Here are the expected values:

0            769 kHz
65497    100 kHz
65100    10 kHz
61124    1 kHz
21000    100 Hz

Note that if a single SPI transaction takes longer than 250ms, you will timeout the internal Watchdog in the T7 and cause it to reset.  In the example VI with 4 bytes that happens if you set the throttle value to 33000 or less.