183 of 318
ZBasic System Library 173 ZX Microcontroller Family OpenI2CSlave Type Subroutine Invocation OpenI2CSlave(slaveAddr) Parameter Method Type Description slaveAddr ByVal Byte The I2C slave address to which to respond. Discussion This subroutine immediately activates the I2C controller in slave mode. 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 I2C channel 0. Slave mode can be canceled by calling CloseI2C(). 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. The table below gives the pin numbers used for the SDA and SCL signals on various ZX devices. SDA and SCL Pins ZX Models SDA SCL ZX-24n, ZX-24s 11, C.1 12, C.0 ZX-40n, ZX-40s 23, C.1 22, C.0 ZX-44n, ZX-44s 20, C.1 19, C.0 ZX-24ne, ZX-24nu 11, C.1 12, C.0 ZX-328n, ZX-328l, ZX-32n, ZX-32l 27, C.4 28, C.5 ZX-1281n 26, D.1 25, D.0 ZX-1280n 44, D.1 43, D.0 ZX-24x 12, C.0 11, C.1 ZX-32a4 10, C.0 11, C.1 ZX-128a1 15, C.0 16, C.1 ZX-128ne, ZX-1281ne 11, D.1 12, D.0 ZX-328nu 21, C4 22, C.5 Example Call OpenI2CSlave(&H50) ' activate I2C slave mode with address &H50 Resource Usage The I2C hardware channel 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