CBUS is a clocked serial bus and is 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
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
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()– “Shifts in” the specified number of bytes
cbusWr()– “Shifts out” the specified bytes
To allow these functions to be as fast as possible, the IO pins used for CBUS CLK, CDATA, and RDATA are fixed. The IO pins that are reserved for CBUS varies by platform, so refer to RF Modules. These pins are not dedicated for CBUS, so if you are not using the CBUS functions, you may use the reserved pins for other functions.
You will also need as many Chip Select (CS) pins as you have external CBUS devices. You can choose any available GPIO pin(s) to be your CBUS CS pins. The basic program flow becomes:
# Select the desired CBUS device, assuming the chip select is active-low writePin(your_cs_pin, False) # Read 10 bytes from the selected CBUS deviceResponse = cbusRd(10) # Deselect the CBUS device, assuming the chip select is active-low writePin(your_cs_pin, True)
CBUS writes are handled in a similar fashion. If you are already familiar with CBUS devices, you should have no trouble using these functions to interface to external CBUS chips.
Not all platforms support CBUS, refer to RF Modules.