Page 213 of 346 Start Back Next End ZBasic System Library 201 ZBasic Microcontrollers OpenSPISlave Type Subroutine Invocation OpenSPISlave(flags) Parameter Method Type Description flags ByVal integral Flags controlling the SPI communication. Discussion This subroutine, available only for native mode devices, immediately activates the hardware SPI controller in slave mode. The flags parameter specifies the characteristics of the SPI communication. They must be set to be compatible with the SPI master with which you want to communicate. See the table below for details. SPI Slave Mode Configuration Bits Function Hex Value Bit Mask Clock Phase False &H00 xx xx x0 xx Clock Phase True &H04 xx xx x1 xx Clock Low at Idle &H00 xx xx 0x xx Clock High at Idle &H08 xx xx 1x xx Bit Order – MSB first &H00 xx 0x xx xx Bit Order – LSB first &H20 xx 1x xx xx For devices that have multiple SPI controllers (e.g. xmega-based devices), the most significant byte of the flags parameter specifies the index of the SPI controller to use (0=PortD, 1=PortC, 2=PortE, 3=PortF). See the tables below for information about which pins of each port are used for the SPI control/data pins. The chip select pin for an SPI slave is a dedicated pin. See the Resource Usage sub-section SPI Controllers for information about the available hardware SPI controllers for the various ZBasic devices and the chip select, control and data pins for each. If you activate slave mode, you must also provide an interrupt handler for the corresponding interrupt vector. While slave mode is active, SPICmd() calls are ineffective for that channel. Slave mode can be canceled by calling CloseSPI(). See OpenSPI() for information about which pins are used for the data and control signals for each SPI controller. Note that the SPI master sets the SPI clock speed. The highest SPI clock speed that can be used reliably is one quarter of the CPU clock speed of a ZX slave device. Depending on how much computation the slave must perform to prepare data for sending back to the master, a substantially slower SPI clock may need to be used. If a ZBasic device is being used as the master, it may be useful to set the rxDelay parameter on calls to OpenSPI() on the master to allow additional processing time. Compatibility This subroutine is only supported for native mode devices. See Also CloseSPI, OpenSPI