Specifications

The SPI support routines in SNAPpy can deal with all these variations, but you will have to make sure
the options you specify in your SNAPpy scripts match the settings required by your external devices.
Like what was done for CBUS devices, dedicated SPI support (master emulation only) has been
added to the set of SNAPpy built-in functions. Four functions (callable from SNAPpy but
implemented in optimized C code) support reading and writing SPI data:
In order to support both three wire and four wire SPI, there are more spiXXX() functions than you
might first expect.
spiInit(cpol, cpha, isMsbFirst, isFourWire) – setup for SPI (many options!)
spiWrite(byteStr, bitsInLastByte=8) – send data out SPI
spiRead(byteCount, bitsInLastByte=8) – receive data in from SPI (3 wire only)
spiXfer(byteStr, bitsInLastByte=8) – bidirectional SPI transfer (4 wire only)
Four-wire SPI interfaces transfer data in both directions simultaneously, and should use the spiXfer()
function.
Some SPI devices are write-only, and you can use spiWrite() to send data to them (three-wire or four-
wire hookup).
Some three wire devices are read-only, and you must use function spiRead().
The data width for SPI devices is not standardized. Devices that use a data width that is a multiple of 8
are trivial (send 2 bytes to make 16 bits total for example). However, device widths such as 12 bits are
common. To support these “non-multiples-of-8”, you can specify how much of the last byte to actually
send or receive. For example,
spiWrite("\x12\x34", 4)
…will send a total of 12 bits: all of the first byte (0x12), and the first (or last) nibble of the second
byte.
Which 4 bits out of the total 8 get sent are a function of the “send LSB first” setting, which is
specified as part of the spiInit() call.
To allow these functions to be as fast as possible, the IO pins used for CLK, MOSI, and MISO are
fixed
. For example, on a Synapse RFE Engine, the following pins are used:
GPIO 12 is always used as the MOSI pin
GPIO 13 is always used as the CLK pin
GPIO 14 is always used as the MISO pin, unless running in three wire mode
(The chip select pin is what raises the total number of pins to 3 or 4)
Page 36 of 202 SNAP Reference Manual Document Number 600-0007K