Navigation bar
  Start Previous page
 181 of 318 
Next page End  

ZBasic System Library
171
ZX Microcontroller Family
where F_CPU is the device’s operating frequency .  If the bitRate parameter is omitted or is zero the
value of 66 is used by default.
Channel 0 Prescaler Selector Value
Value
Divisor
0
1
1
4
2
16
3
64
For ATxmega-based devices, the I2C bit rate is given by the formula F_CPU / 2 / (5 + rateVal)
where rateVal is the low 8 bits of the bitRate parameter.  Rearranging this formula gives an equation
for the bitRate parameter: bitRate = (F_CPU / 2 / F_I2C) – 5 where F_I2C is the desired
I2C clock frequency.
For channels 1-4 the bitRate parameter is interpreted as the number of I/O Timer ticks per bit.   For I2C
operations, the I/O Timer uses the prescaler specified by Register.TimerSpeed1.  With the default
prescaler of 1, each I/O Timer tick represents approximately 68nS.  If the bitRate parameter is omitted
or is zero the value of 74 is used by default.  Due to processing overhead, the minimum attainable bit time
is approximately 4µS.
For channel 0, the table below gives the pin numbers used for SDA and SCL.
SDA and SCL Pins
ZX Models
SDA
SCL
ZX-24, ZX-24a, ZX-24p, ZX-24n, ZX-24r, ZX-24s
11, C.1
12, C.0
ZX-40, ZX-40a, ZX-40p, ZX-40n, ZX-40r, ZX-40s
23, C.1
22, C.0
ZX-44, ZX-44a, ZX-44p, ZX-44n, ZX-44r, ZX-44s
20, C.1
19, C.0
ZX-24e, ZX-24ae, ZX-24ne, ZX-24pe, ZX-24nu, ZX-24pu
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-24x
12, C.0
11, C.1
ZX-32a4
10, C.0
11, C.1
ZX-128a1
15, C.0
16, C.1
ZX-128e, ZX-128ne, ZX-1281e, ZX-1281ne
11, D.1
12, D.0
ZX-328nu
21, C4
22, C5
As noted above, the sdaPin parameter value is ignored when channel 0 is specified.
Examples
Call OpenI2C(0, 0, 0)
' open the hardware channel at 100KHz
Call OpenI2C(2, 19, 20) 
' open channel 2 using pins 19, 20
Call OpenI2C(1, C.3, A.1, 74) 
' open channel 1 at 200KHz
Resource Usage
The I2C routines utilize the I/O Timer to regulate the bit timing for channels 1-4.  While sending or
receiving I2C data, the corresponding timer busy flag will be True indicating that the I/O Timer is in use. 
On the ZX-24n, ZX-24p, ZX-24r and ZX-24s, the hardware I2C channel cannot be used while Com2 is
open since pin 11 is shared by the SDA signal and TxD for Com2.
Previous page Top Next page