Page 206 of 346 Start Back Next End ZBasic System Library 194 ZBasic Microcontrollers OpenI2CSlave Type Subroutine Invocation OpenI2CSlave(slaveAddr) OpenI2CSlave(slaveAddr, channel) Parameter Method Type Description slaveAddr ByVal Byte The I2C slave address to which to respond. channel ByVal Byte The I2C channel to open (0-4). Discussion This subroutine immediately activates the I2C controller in slave mode. If the optional channel parameter is not given, channel 0 is assumed. Note that use of channels 1-4 are supported only on devices that have multiple I2C controllers (e.g. ATxmega devices). See the description of OpenI2C for more details about the correspondence between channel numbers and hardware controllers. If you activate slave mode, you must also provide an interrupt handler for the TWI vector (aka the I2C vector). While slave mode is active, calls to CmdI2C() and the low level I2C commands are ineffective for the I2C channel in use. Slave mode can be canceled by calling CloseI2C(), specifying the channel number specified or implied in the call to OpenI2Cslave(). While slave mode is active, the device will respond to reads and writes on the I2C bus referring to its slave address which is the value of the slaveAddr parameter with the least significant bit set to zero. If the least significant bit of the slaveAddr parameter is set, the slave can respond also to “general call” traffic on the bus. See the Resource Usage subsection I2C Controllers for information on the available I2C hardware channels and the corresponding clock and data pins. Example Call OpenI2CSlave(&H50) ' activate I2C slave mode with address &H50 Resource Usage The I2C hardware channel in use cannot be opened by OpenI2C() while slave mode is active. On the ZX-24n, and ZX-24s, I2C slave mode cannot be used while Com2 is open since pin 11 is shared by the SDA signal and TxD for Com2. Compatibility This subroutine is only available for native mode devices. See Also CloseI2C, OpenI2C