User manual

7. Advanced SNAPpy Topics
This secon describes how to use some of the more advanced features of SNAP. Topics covered include:
Interfacing to external CBUS slave devices (emulang a CBUS master)
Interfacing to external SPI slave devices (emulang a SPI master)
Interfacing to external I
2
C slave devices (emulang a I2C master)
Interfacing to mul-drop RS-485 devices
Encrypon between SNAP nodes
Recovering an unresponsive node
Interfacing to external CBUS slave devices
CBUS is a clocked serial bus, similar to SPI. It requires at least four pins:
CLK master ming reference for all CBUS transfers
CDATA data from the CBUS master to the CBUS slave
RDATA data from the CBUS slave to the CBUS master
CS At least one Chip Select (CS)
Using the exisng readPin() and writePin() funcons, virtually any type of device can be interacted with via a
SNAPpy script, including external CBUS slaves. Arbitrarily chosen GPIO pins could be configured as inputs or
outputs by using the setPinDir() funcon. The CLK, CDATA, and CS pins would be controlled using the writePin()
funcon. The RDATA pin would be read using the readPin() funcon.
The problem with a strictly SNAPpy based approach is speed CBUS devices tend to be things like voice chips,
with strict ming requirements. Opmized nave code may be preferred over the SNAPpy virtual machine in
such cases.
To solve this problem, dedicated CBUS support (master emulaon only) has been added to the set of SNAPpy
built-in funcons. Two funcons (callable from SNAPpy but implemented in opmized C code) support reading
and wring CBUS data:
cbusRd(numToRead)“shis in” the specified number of bytes
cbusWr(str)“shis out” the bytes specified by str
To allow the cbusRd() and cbusWr() funcons to be as fast as possible, the IO pins used for CBUS CLK, CDATA,
and RDATA are fixed. On an RF100 SNAP Engine:
GPIO 12 is always used as the CBUS CDATA pin
GPIO 13 is always used as the CBUS CLK pin
GPIO 14 is always used as the CBUS RDATA pin
For plaorms other than the RF100, refer to the appropriate plaorm specific secon in the back of the SNAP
Reference Manual.
NOTEThese pins are only dedicated if you are actually using the CBUS funcons. If not, they remain
available for other funcons.
You will also need as many Chip Select pins as you have external CBUS devices. You can choose any available
GPIO pin(s) to be your CBUS chip selects. The basic program flow becomes:
# select the desired CBUS device
writePin(somePin, False) # assuming the chip select is active-low
38 SNAP® Network Operang System