Skip to main content
Skip table of contents

4.34 - Synch [U12 Datasheet]

Requires firmware V1.1 or higher. This function performs SPI communication. Data rate is about 160 kbps with no extra delay, although delays of 100 us or 1 ms per bit can be enabled.

Execution time for this function is about 20 milliseconds to write and/or read up to 4 bytes, plus about 20 milliseconds for each additional 4 bytes written or read. Extra 20 milliseconds if configD is true, and extra time if delays are enabled.

Control of CS (chip select) can be enabled in this function for D0-D7 or handled externally via any digital output.

MOSI is D13
MISO is D14
SCK is D15

If using the CB25, the protection resistors might need to be shorted on all SPI connections (MOSI, MISO, SCK, CS).

The initial state of SCK is set properly (CPOL), by this function, before !CS is brought low (final state is also set properly before !CS is brought high again). If chip-select is being handled manually, outside of this function, care must be taken to make sure SCK is initially set to CPOL.

All modes supported (A, B, C, and D).

Mode A: CPHA=1, CPOL=1
Mode B: CPHA=1, CPOL=0
Mode C: CPHA=0, CPOL=1
Mode D: CPHA=0, CPOL=0

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 18 bytes can be written/read. Communication is full duplex so 1 byte is read at the same time each byte is written. If more than 4 bytes are written or read, this function uses calls to WriteMem/ReadMem to load/read the LabJack’s data buffer.

This function has the option (configD) to automatically configure default state and direction for MOSI (D13 Output), MISO (D14 Input), SCK (D15 Output CPOL), and CS (D0-D7 Output High for !CS). This function uses a call to DigitalIO to do this. Similar to EDigitalIn and EDigitalOut, the DLL keeps track of the current direction and output state of all lines, so that these 4 D lines can be configured without affecting other digital lines. When the DLL is first loaded, though, it does not know the direction and state of the lines and assumes all directions are input and output states are low.


long Synch ( long *idnum,
long demo,
long mode,
long msDelay,
long husDelay,
long controlCS,
long csLine,
long csState,
long configD,
long numWriteRead,
long *data )

Parameter Description:
Returns: LabJack errorcodes or 0 for no error.

  • *idnum – Local ID, serial number, or -1 for first found.
  • demo – Send 0 for normal operation, >0 for demo mode. Demo mode allows this function to be called without a LabJack.
  • mode – Specify SPI mode as: 0=A,1=B,2=C,3=D (0-3).
  • msDelay – If >0, a 1 ms delay is added between each bit.
  • husDelay – If >0, a hundred us delay is added between each bit.
  • controlCS – If >0, D0-D7 is automatically controlled as CS. The state and direction of CS is only tested if control is enabled.
  • csLine – D line to use as CS if enabled (0-7).
  • csState – Active state for CS line. This would be 0 for the normal !CS, or >0 for the less common CS.
  • configD – If >0, state and tris are configured for D13, D14, D15, and !CS.
  • numWriteRead – Number of bytes to write and read (1-18).
  • *data – Serial data buffer. Send an 18 element array of bytes. Fill unused locations with zeros.


  • *idnum – Returns the local ID or –1 if no LabJack is found.
  • *data – Serial data buffer. Returns any serial read data. Unused locations are filled with 9999s.

ActiveX Function Differences:
The maximum number of bytes to write/read is limited to 5 (numWriteRead should be 1-5). The data array is replaced with pointers to 5 individual data bytes.

Declaration (ActiveX):

long SynchX ( long FAR* idnum,
long demo,
long mode,
long msDelay,
long husDelay,
long controlCS,
long csLine,
long csState,
long configD,
long numWriteRead,
long FAR* data0,
long FAR* data1,
long FAR* data2,
long FAR* data3,
long FAR* data4,
long FAR* data5 )

JavaScript errors detected

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

If this problem persists, please contact our support.