User manual
Some three wire devices are read-only, and you must use funcon spiRead().
The data width for SPI devices is not standardized. Devices that use a data width that is a mulple 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-mulples-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” seng, which is specified as part of the
spiInit() call.
To allow these funcons 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)
NOTE – These pins are only dedicated if you are actually using the SPI funcons. If not, they remain
available for other funcons. Also, if using three wire SPI, GPIO 14 remains available.
For plaorms other than the RF100, refer to the appropriate plaorm specific secon 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 funcons 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 funcons within it.
• ZIC2410spiTests.py – like spiTests.py but specifically for ZIC2410 evaluaon board
• AT25FS010.py – Example of interfacing to an ATMEL Flash memory
Script ZIC2410spiTests.py imports the other script, and exercises some of the funcons within it.
40 SNAP® Network Operang System