![Nuvoton NuMicro MS51 32K Series Скачать руководство пользователя страница 412](http://html1.mh-extra.com/html/nuvoton/numicro-ms51-32k-series/numicro-ms51-32k-series_technical-reference-manual_1720303412.webp)
MS51
Nov. 28, 2019
Page
412
of 491
Rev 1.00
MS51
32K
SE
RIES
TE
CHNICAL RE
F
EREN
CE MA
N
UAL
Since control of the I
2
C bus is decided solely on the address or master code and data sent by
competing masters, there is no central master, nor any order of priority on the bus. Slaves are not
involved in the arbitration procedure.
Operation Modes
6.11.2.5
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_CTL0, I2C_DAT registers
according to current status code of I2C_STATUS0 register. In other words, for each I
2
C bus action,
user needs to check current status by I2C_STATUS0 register, and then set I2C_CTL0, I2C_DAT
registers to take bus action. Finally, check the response status by I2C_STATUS0.
The bits, STA, STO and AA in I2C_CTL0 register are used to control the next state of the I
2
C
hardware after SI flag of I2C_CTL0 [3] register is cleared. Upon completion of the new action, a new
status code will be updated in I2C_STATUS0 register and the SI flag of I2C_CTL0 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_CTL0 [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 Control I2C Bus according to the Current I2C Status 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_STATUS0 will be updated
by status code 0x18.
S
I2C_DAT
(SLA+W)
ACK
Last Status
STATUS=0x08
Updated Status
STATUS=0x18
Register Control
I2C_DAT=SLA+W
(STA,STO,SI,AA)=(0,0,1,x)
Master to Slave
Slave to Master
Figure 6.11-9 Control I
2
C Bus according to the Current I
2
C Status
Master Transmitter Mode
In the master transmitter mode, several bytes of data are transmitted to a slave receiver. The master
should prepare by setting desired clock rate in I2CnCLK. The master transmitter mode may now be
entered by setting STA (I2CnCON.5) bit as 1. The hardware will test the bus and generate a START
condition as soon as the bus becomes free. After a START condition is successfully produced, the SI
flag (I2CnCON.3) will be set and the status code in I2CnSTAT show 08H. The progress is continued
by loading I2
CnDAT with the target slave address and the data direction bit “write” (SLA+W). The SI
bit should then be cleared to commence SLA+W transaction.
After the SLA+W byte has been transmitted and an acknowledge (ACK) has been returned by the
addressed slave device, the SI flag is set again and I2CnSTAT is read as 18H. The appropriate action
to be taken follows user defined communication protocol by sending data continuously. After all data is
transmitted, the master can send a STOP condition by setting STO (I2CnCON.4) and then clearing SI