MS51
Dec. 17, 2019
Page
275
of 316
Rev 1.01
M
S51
SE
RIES
TE
CHNICA
L REF
ERE
N
CE MA
NU
A
L
There is a 14-bit time-out counter, which can be used to deal with the I
2
C bus hang-up. If the time-out
counter is enabled, the counter starts up counting until it overflows. Meanwhile I2TOF will be set by
hardware and requests I
2
C interrupt. When time-out counter is enabled, setting flag SI to high will
reset counter and restart counting up after SI is cleared. If the I
2
C bus hangs up, it causes the SI flag
not set for a period. The 14-bit time-out counter will overflow and require the interrupt service.
1
0
F
SYS
1/4
14-bit I
2
C Time-out Counter
I2TOF
Clear Counter
I2TOCEN
DIV
I2CEN
SI
Figure 6.10-14 I
2
C Time-Out Counter
6.10.5
I
2
C Interrupt
There are two I
2
C flags, SI and I2TOF. Both of them can generate an I
2
C event interrupt requests. If
I
2
C interrupt mask is enabled via setting EI2C and EA as 1, CPU will execute the I
2
C interrupt service
routine once any of these two flags is set. User needs to check flags to determine what event caused
the interrupt. Both of I
2
C flags are cleared by software.
6.10.6
Control Registers
There are five control registers to interface the I
2
C bus including I2CON, I2STAT, I2DAT, I2ADDR,
and I2CLK. These registers provide protocol control, status, data transmitting and receiving functions,
and clock rate configuration. For application flexibility, I2C0_SDA and I2C0_SCL pins can be
exchanged by I2CPX (I2CON.0). The following registers relate to I
2
C function.
I2CON
– I
2
C Control
Regiser
Address
Reset Value
I2CON
C0H, all pages, Bit addressable
0000_0000 b
7
6
5
4
3
2
1
0
I
I2CEN
STA
STO
SI
AA
-
I2CPX
R/W
R/W
R/W
R/W
R/W
R/W
-
R/W
Bit
Name
Description
7
I
I2C0 hold time extend enable
0 = I
2
C DATA to I2C0_SCL hold time extend disabled
1 = I
2
C DATA to I2C0_SCL hold time extend enabled, extend 8 system clock
6
I2CEN
I2C bus enable
0 = I
2
C bus Disabled.
1 = I
2
C bus Enabled.
Before enabling the I2C, I2C0_SCL and I2C0_SDA port latches should be set to logic 1.