ZBasic System Library
162
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-24, ZX-24a, ZX-24p, ZX-24n
11, C.1
12, C.0
ZX-40, ZX-40a, ZX-40p, ZX-40n
23, C.1
22, C.0
ZX-44, ZX-44a, ZX-44p, ZX-44n
20, C.1
19, C.0
ZX-24e, ZX-24ae, ZX-24pe, ZX-24ne
11, C.1
12, C.0
ZX-328n, ZX-328l, ZX-32n, ZX-32l
27, C.4
28, C.5
ZX-1281, ZX-1281n
26, D.1
25, D.0
ZX-1280, ZX-1280n
44, D.1
43, D.0
ZX-128e, ZX-128ne, ZX-1281e, ZX-1281ne
11, D.1
12, D.0
ZX-328nu
21, C4
22, C.5
Examples
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,
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