User manual

# read bytes from the selected CBUS device
Response = cbusRd(10) # <- you specify how many bytes to read
# deselect the CBUS device
writePin(somePin, True) # assuming the chip select is active-low
CBUS writes are handled in a similar fashion.
If you are already familiar with CBUS devices, you should have no trouble using these funcons to interface to
external CBUS chips.
A detailed example of interfacing to an external CBUS voice chip may someday be the topic of an applicaon
note.
NOTENot all SNAP Engines support CBUS, refer to the SNAP Reference Manual.
Interfacing to external SPI slave devices
SPI is another clocked serial bus. It typically requires at least four pins:
CLK master ming reference for all SPI transfers
MOSI Master Out Slave In data line FROM the master TO the slave devices
MISO Master In Slave Out data line FROM the slaves TO the master
CS At least one Chip Select (CS)
SPI also exists in a three wire variant, with the MOSI pin serving double-duty.
Numerous opons complicate use of SPI:
Clock Polarity the clock signal may or may not need to be inverted
Clock Phase the edge of the clock actually used varies between SPI devices
Data Order some devices expect/require Most Significant Bit (MSB) first, others only work Least
Significant Bit (LSB) first
Data Width some SPI devices are 8-bit, some are 12, some are 16, etc.
You can find more informaon on SPI at hp://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus
The SPI support rounes in SNAPpy can deal with all these variaons, but you will have to make sure the opons
you specify in your SNAPpy scripts match the sengs required by your external devices.
As with what was done for CBUS devices, dedicated SPI support (master emulaon only) has been added to the
set of SNAPpy built-in funcons. Four funcons (callable from SNAPpy but implemented in opmized C code)
support reading and wring SPI data.
In order to support both three wire and four wire SPI, there are more spiXXX() funcons than you might first
expect.
spiInit(cpol, cpha, isMsbFirst, isFourWire)setup for SPI (supporng many opons!)
spiWrite(byteStr, bitsInLastByte=8)send data out SPI
spiRead(byteCount, bitsInLastByte=8)receive data in from SPI (3 wire only)
spiXfer(byteStr, bitsInLastByte=8)bidireconal SPI transfer (4 wire only)
Four-wire SPI interfaces transfer data in both direcons simultaneously, and should use the spiXfer() funcon.
Some SPI devices are write-only, and you can use spiWrite() to send data to them (three-wire or four-wire
hookup).
SNAP® Network Operang System 39