
NUC126
Aug. 08, 2018
Page
349
of 943
Rev 1.03
NUC12
6 S
E
RI
E
S
T
E
CH
NI
CA
L R
E
F
E
RE
NCE
MA
NUA
L
A = acknowledge (SDA low)
A = not acknowledge (SDA high)
S = START condition
P = STOP condition
‘0’ : write
S
SLAVE ADDRESS
R/W
A
DATA
A
DATA
A/A
P
from master to slave
from slave to master
data transfer
(n bytes + acknowlegde)
Figure 6.11-7 Master Transmits Data to Slave by 7-bit
Figure 6.11-8 shows a master read data from slave by 7-bit. A master addresses a slave with a 7-bit
address and 1-bit read index to denote that the master wants to read data from the slave. The slave
will start transmitting data after the slave returns acknowledge to the master.
‘1’ : read
S
SLAVE ADDRESS
R/W
A
DATA
A
DATA
A/A
P
data transfer
(n bytes + acknowlegde)
Figure 6.11-8 Master Reads Data from Slave
by 7-bit
6.11.5.2 Operation Modes
The on-chip I
2
C ports support three operation modes, Master, Slave, and General Call Mode.
In a given application, I
2
C port may operate as a master or as a slave. In Slave mode, the I
2
C port
hardware looks for its own slave address and the general call address. If one of these addresses is
detected, and if the slave is willing to receive or transmit data from/to master(by setting the AA bit),
acknowledge pulse will be transmitted out on the 9th clock, hence an interrupt is requested on both
master and slave devices if interrupt is enabled. When the microcontroller wishes to become the bus
master, hardware waits until the bus is free before entering Master mode so that a possible slave
action is not be interrupted. If bus arbitration is lost in Master mode, I
2
C port switches to Slave mode
immediately and can detect its own slave address in the same serial transfer.
To control the I
2
C bus transfer in each mode, user needs to set I2C_CTL, I2C_DAT registers
according to current status code of I2C_STATUS register. In other words, for each I
2
C bus action, user
needs to check current status by I2C_STATUS register, and then set I2C_CTL, I2C_DAT registers to
take bus action. Finally, check the response status by I2C_STATUS.
The bits, STA, STO and AA in I2C_CTL register are used to control the next state of the I
2
C hardware
after SI (I2C_CTL [3]) register is cleared. Upon completion of the new action, a new status code will be
updated in I2C_STATUS register and the SI flag of I2C_CTL register will be set. But the SI flag will not
be set when I
2
C STOP. If the I
2
C interrupt control bit INTEN (I2C_CTL [7]) is set, appropriate action or
software branch of the new status code can be performed in the Interrupt service routine.
Figure 6.11-9 shows the current I
2
C status code is 0x08, and then set I2C_DATA=SLA+W and
(STA,STO,SI,AA) = (0,0,1,x) to send the address to I
2
C bus. If a slave on the bus matches the address
and response ACK, the I2C_STATUS will be updated by status code 0x18.