Specifications

6. Advanced SNAPpy Topics
This section describes how to use some of the more advanced features of SNAP. Topics covered
include:
Interfacing to external CBUS slave devices (emulating a CBUS master)
Interfacing to external SPI slave devices (emulating a SPI master)
Interfacing to external I2C slave devices (emulating a I2C master)
Interfacing to multi-drop RS-485 devices
Encryption 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 timing 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 existing readPin() and writePin() functions, 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() function. The CLK, CDATA, and CS pins
would be controlled using the writePin() function. The RDATA pin would be read using the readPin()
function.
The problem with a strictly SNAPpy based approach is speed – CBUS devices tend to be things like
voice chips, with strict timing requirements. Optimized native code may be preferred over the
SNAPpy virtual machine in such cases.
To solve this problem, dedicated CBUS support (master emulation only) has been added to the set of
SNAPpy built-in functions. Two functions (callable from SNAPpy but implemented in optimized C
code) support reading and writing CBUS data:
cbusRd(numToRead) – “shifts in” the specified number of bytes
cbusWr(str) – “shifts out” the bytes specified by str
To allow the cbusRd() and cbusWr() functions 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
Page 34 of 202 SNAP Reference Manual Document Number 600-0007K