User manual
7. Advanced SNAPpy Topics
This secon describes how to use some of the more advanced features of SNAP. Topics covered include:
• Interfacing to external CBUS slave devices (emulang a CBUS master)
• Interfacing to external SPI slave devices (emulang a SPI master)
• Interfacing to external I
2
C slave devices (emulang a I2C master)
• Interfacing to mul-drop RS-485 devices
• Encrypon 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 exisng readPin() and writePin() funcons, 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() funcon. The CLK, CDATA, and CS pins would be controlled using the writePin()
funcon. The RDATA pin would be read using the readPin() funcon.
The problem with a strictly SNAPpy based approach is speed – CBUS devices tend to be things like voice chips,
with strict ming requirements. Opmized nave code may be preferred over the SNAPpy virtual machine in
such cases.
To solve this problem, dedicated CBUS support (master emulaon only) has been added to the set of SNAPpy
built-in funcons. Two funcons (callable from SNAPpy but implemented in opmized C code) support reading
and wring CBUS data:
•
cbusRd(numToRead) – “shis in” the specified number of bytes
•
cbusWr(str) – “shis out” the bytes specified by str
To allow the cbusRd() and cbusWr() funcons 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 plaorms other than the RF100, refer to the appropriate plaorm specific secon in the back of the SNAP
Reference Manual.
NOTE– These pins are only dedicated if you are actually using the CBUS funcons. If not, they remain
available for other funcons.
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 Operang System