Specifications

spiInit(cpol, cpha, isMsbFirst, isFourWire) – Setup SPI Bus
This function initializes the SNAP node to perform Serial Peripheral Interface (SPI) Bus interfacing.
The SPI standard supports multiple options, hence the large number of parameters in spiInit().
Parameter cpol refers to Clock Polarity, and can be either True or False. Basically it specifies the level
of the CLK pin between SPI exchanges. To put it another way, cpol specifies the idle clock level.
Parameter cpha refers to the Clock Phase, and can be True or False. It specifies which clock edge the
incoming data is to be “latched in.” If you number clock edges from 1, then setting cpha = True
specifies the even clock edges for incoming data, and setting cpha = False specifies the odd clock
edges for incoming data.
Because SPI mode is specified using both a cpol and cpha setting, there are four possible
combinations. Which combination is correct depends on the device you are interfacing to; refer to
the manufacturer’s data sheets.
Parameter isMsbFirst controls the order in which individual bits within each byte will be shifted out.
Setting this parameter to True will make the 0x80 bit go out first, setting this parameter to False will
make the 0x01 bit go out first.
Again, the correct setting for the isMsbFirst parameter depends on the device to which you are
interfacing.
Parameter isFourWire lets you select the variant of SPI you are connecting to. Three wire SPI omits
the MISO pin. In three-wire SPI, even if the slave does send data, it is over the MOSI pin.
This function does not return a value.
spiRead(byteCount, bitsInLastByte=8) – SPI Bus Read
This function can only be used after function spiInit() has been called.
This function reads data from a three wire SPI device (for four wire SPI, you should be using the
bidirectional function spiXfer() instead).
Parameter byteCount specifies how many bytes to read.
Parameter bitsInLastByte makes it possible to accommodate devices with data widths that are not
multiples of 8 (like 12 bits). The default value of bitsInLastByte is 8. For a device with a data width of
12 bits, bitsInLastByte would be set to 4. For a device with a data width of 31 bits, bitsInLastByte
would be set to 7.
The order that bits get shifted in depends on the value of parameter isMsbFirst which was specified in
the previous spiInit() call.
SNAP Reference Manual Document Number 600-0007K Page 75 of 202