5.2.17 - SPI
Sends and receives serial data using SPI synchronous communication.
- NumSPIWords: This is the number of SPI bytes divided by 2. If the number of SPI bytes is odd, round up and add an extra zero to the packet.
- SPIOptions: If AutoCS is true, the CS line is automatically driven low during the SPI communication and brought back high when done. If DisableDirConfig is true, this function does not set the direction of the lines, whereas if it is false the lines are configured as CS=output, CLK=output, MISO=input, and MOSI=output. SPIMode specifies the standard SPI mode as discussed below.
- SPIClockFactor: Sets the frequency of the SPI clock according the following approximate formula: Frequency = 1000000/(10+10*(256-SPIClockFactor), where passing a value of 0 corresponds to a factor of 256, and thus a maximum frequency of about 100 kHz.
- Advanced Options: Bit [2:0] allow the number of bits to be transfered during the final byte to be specified, where 0 = 8. This makes it possible to transfer any number of bits within packet size limitations. For example, to transfer 11 bits set the number of bytes to 2 and set bits [2:0] of the advanced options to 3. The LabJack will transfer a full byte of 8 bits, then transfer 3 more bits. The 3 most significant bits in the final byte will be sent and data read during those bits will be in the most significant bits of the final byte in the data. This feature requires firmware 1.21.
- CS/CLK/MISO/MOSI -PinNum: Assigns which digital I/O line is used for each SPI line. Value passed is 0-19 corresponding to the normal digital I/O numbers as specified in Section 2.8.
- NumSPIBytesToTransfer: Specifies how many SPI bytes will be transferred (1-50).
The initial state of SCK is set properly (CPOL), by this function, before CS (chip select) is brought low (final state is also set properly before CS is brought high again). If CS is being handled manually, outside of this function, care must be taken to make sure SCK is initially set to CPOL before asserting CS.
All standard SPI modes supported (A, B, C, and D).
Mode A: CPHA=0, CPOL=0
Mode B: CPHA=0, CPOL=1
Mode C: CPHA=1, CPOL=0
Mode D: CPHA=1, CPOL=1
If Clock Phase (CPHA) is 1, data is valid on the edge going to CPOL. If CPHA is 0, data is valid on the edge going away from CPOL. Clock Polarity (CPOL) determines the idle state of SCK.
Up to 50 bytes can be written/read. Communication is full duplex so 1 byte is read at the same time each byte is written.
Datasheets and User Guides
- UD Series (U3, U6, UE9)
- U3
- U6
- User's Guide
- Preface
- 1 - Installation on Windows
- 2 - Hardware Description
- 3 - Operation
- 4 - LabJackUD High-Level Driver
- 5 - Low-level Function Reference
- 5.1 - General Protocol
- 5.2 - Low-Level Functions
- 5.2.1 - Bad Checksum
- 5.2.2 - ConfigU6
- 5.2.3 - ConfigIO
- 5.2.4 - ConfigTimerClock
- 5.2.5 - Feedback
- 5.2.6 - ReadMem (ReadCal)
- 5.2.7 - WriteMem (WriteCal)
- 5.2.8 - EraseMem (EraseCal)
- 5.2.9 - SetDefaults (SetToFactoryDefaults)
- 5.2.10 - ReadDefaults (ReadCurrent)
- 5.2.11 - Reset
- 5.2.12 - StreamConfig
- 5.2.13 - StreamStart
- 5.2.14 - StreamData
- 5.2.15 - StreamStop
- 5.2.16 - Watchdog
- 5.2.17 - SPI
- 5.2.18 - AsynchConfig
- 5.2.19 - AsynchTX
- 5.2.20 - AsynchRX
- 5.2.21 - I²C
- 5.2.22 - SHT1X
- 5.2.23 1-Wire
- 5.3 - Errorcodes
- 5.4 - Calibration Constants
- Appendix A - Specifications
- Appendix B - Noise and Resolution Tables
- Appendix C - Enclosure and PCB Drawings
- U6 Firmware Revision History
- User's Guide
- UE9
- U12
- Digit Series
- T Series
Search
Shopping Cart
Testimonials
-
I don't know of many other companies that provide such excellent service. I wouldn't hesitate to recommend your product to anyone.
—Richard, Milwaukee School of Engineering


Comments
#1
Just pointing out a minor error, byte 7 should be SPIClockFactor in the table. Thanks!
#2
Fixed. Thanks.
#3
Hi Everyone:
The modes listed for the U6 above appear to be incorrect; they don't match those listed for the U3 or U9 and judging from hooking the U6 up to an o-scope they should in fact match the modes for U3/U9. I figured this out while trying to operate an IC in mode A above, only to figure out that I needed to use mode D to get correct operation of my device (then looked on a scope to realize the clock phase and polarity was what I wanted it to be when using mode D). Thanks!
#4
Thank you for catching that.
Page updated.