Additional I/O can be obtained utilizing the built-in SPI
(Serial Peripheral Interface) capabilities of the LabJack along with 74HC165 or CD4094
IC's for additional inputs or outputs, respectively. A maximum of 144 additional
I/O bits can be added using a single SPI chain.
The basic process of expanding I/O is shown below, which illustrates the
addition of 16 outputs and 16 inputs.
The IC's are connected in a daisy chain. To obtain additional I/O,
insert one or more IC's into the chain.
The hardware above requires the SPI hardware to run in Mode 2.
The LabJack SPI mode pin-out is shown in the following table.
Signal |
LabJack Pin |
MOSI |
D13 |
MISO |
D14 |
SCK |
D15 |
CSN |
User selectable, D0-D7 |
The following sample code utilizes the LabJackWrapper class
to read and write I/O.
LabJackWrapper labjack = new LabJackWrapper( -1 );
int spiMode = 2; // need mode 2 for proper readback with CD4094 and 74HC165 IC's
int spiMsDelay = 0; // no delay between bits (go fast)
int spiHusDelay = 0; // no delay between bits (go fast)
int spiControlCS = 1; // >1 means we want LabJack to implement and control a chip select pin for us
int spiCsLine = 0; // '0' means use D0 as the chip select line
int spiCsState = 0; // specify active state (low) of chip select line, i.e. CSN
int spiConfigD = 1; // we want LabJack to configure I/O pins for us
labjack.configSPI( spiMode, spiMsDelay, spiHusDelay, spiControlCS, spiCsLine, spiCsState, spiConfigD );
GenericSPI u1 = new GenericSPI( 8 ); // CD4094
GenericSPI u2 = new GenericSPI( 8 ); // CD4094
GenericSPI u3 = new GenericSPI( 8 ); // 74HC165
GenericSPI u4 = new GenericSPI( 8 ); // 74HC165
// note: add devices starting with first device in SPI chain (first shift register).
labjack.addSPI( u1 );
labjack.addSPI( u2 );
labjack.addSPI( u3 );
labjack.addSPI( u4 );
u1.setBits( 0xaa );
u2.setBits( 0x55 );
labjack.updateSPI();
System.out.println( "read: " + u3.getBits() + ", " + u4.getBits() );
|