185 of 323
ZBasic System Library 175 ZX Microcontroller Family 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. See the description of OpenI2C for more details about the correspondance 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. 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, ZX-24xu 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 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.