5.14 - SPI [U12 Datasheet]
Sends and receives data synchronously (SPI). First four bytes sent/received are passed in this call, and copied to the first 4 bytes of RAM buffer (first 4 bytes of RAM transmit buffer are never used). Any additional bytes must be written/read with the RAM. Baud rate with no delay is about 160 kpbs.
Table 5.14-1.
Command |
|
Byte # | Description |
0 | Data Byte 3 |
1 | Data Byte 2 |
2 | Data Byte 1 |
3 | Data Byte 0 |
4 | Bit 7: ms Delay |
| Bit 6: Hundred µs Delay |
| Bits 5-4: XX |
| Bit 3: SPI Mode D |
| Bit 2: SPI Mode C |
| Bit 1: SPI Mode B |
| Bit 0: SPI Mode A |
5 | 011XXX10 (SPI) |
6 | Number of bytes to write/read (1-18) |
7 | Bit 7: Control CS |
| Bit 6: State of Active CS |
| Bits 5-3: XXX |
| Bits 2-0: D line to use as CS (0-7) |
|
|
Response |
|
Byte # | Description |
0 | Data Byte 3 |
1 | Data Byte 2 |
2 | Data Byte 1 |
3 | Data Byte 0 |
4 | Bits 7-4: XXXX |
| Bit 3: CSStateTris Error Flag |
| Bit 2: SCKTris Error Flag |
| Bit 1: MISOTris Error Flag |
| Bit 0: MOSITris Error Flag |
5 | 011XXX10 (Echo of byte 5) |
6 | Echo of byte 6 from Command |
7 | Echo of byte 7 from Command |
LabJackPython Example
>>> import u12
>>> d = u12.U12(debug=True)
open called
Writing: [0x0, 0x0, 0x0, 0x0, 0x0, 0x57, 0x0, 0x0]
Received: [0x57, 0x0, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0]
>>> d.rawSPI([1,2,3,4], NumberOfBytesToWriteRead = 4)
Writing: [0x4, 0x3, 0x2, 0x1, 0x1, 0x62, 0x4, 0x0]
Received: [0x4, 0x3, 0x2, 0x1, 0x1, 0x62, 0x4, 0x0]
{
'DataByte3': 4, 'DataByte2': 3, 'DataByte1': 2, 'DataByte0': 1,
'ErrorFlags':
<BitField object: [ CSStateTris Error Flag = 0 (0),
SCKTris Error Flag = 0 (0),
MISOTris Error Flag = 0 (0),
MOSITris Error Flag = 1 (1) ] >
}