User manual

Some three wire devices are read-only, and you must use funcon spiRead().
The data width for SPI devices is not standardized. Devices that use a data width that is a mulple 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-mulples-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 specified by the “send LSB first” seng, which is specified as part of the
spiInit() call.
To allow these funcons to be as fast as possible, the IO pins used for CLK, MOSI, and MISO are fixed. For
example, on a Synapse RF100 SNAP 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 from 3 to 4)
NOTEThese pins are only dedicated if you are actually using the SPI funcons. If not, they remain
available for other funcons. Also, if using three wire SPI, GPIO 14 remains available.
For plaorms other than the RF100, refer to the appropriate plaorm specific secon in the back of the SNAP
Reference Manual.
You will also need as many Chip Select pins as you have external SPI devices. You can choose any available GPIO
pin(s) to be your SPI chip selects. The basic program flow becomes:
1. # select the desired SPI device
2. writePin(somePin, False) # assuming the chip select is active-low
3. # Transfer data to the selected SPI device
4. spiWrite(“\x12\x34\x56”)
5. # deselect the SPI device
6. writePin(somePin, True) # assuming the chip select is active-low
SPI reads are handled in a similar fashion.
The specifics of which bytes to send to a given SPI slave device (and what the response will look like) depend on
the SPI device itself. You will have to refer to the manufacturer’s data sheet for any given device to which you
wish to interface.
For examples of using the SNAPpy SPI funcons to interface to external devices, see the following scripts that
are bundled with Portal:
spiTests.py This is the overall SPI demo script
LTC2412.py Example of interfacing to a 24-bit Analog To Digital convertor
Script spiTests.py imports the other script, and exercises some of the funcons within it.
ZIC2410spiTests.py like spiTests.py but specifically for ZIC2410 evaluaon board
AT25FS010.py Example of interfacing to an ATMEL Flash memory
Script ZIC2410spiTests.py imports the other script, and exercises some of the funcons within it.
40 SNAP® Network Operang System