GD32W51x User Manual
638
19.3.7.
I2C slave mode
Initialization
When works in slave mode, at least one slave address should be enabled. Slave address 1
can be programmed in I2C_SADDR0 register and slave address 2 can be programmed in
I2C_SADDR1 register. ADDRESSEN in I2C_SADDR0 register and ADDRESS2EN in
I2C_SADDR1 register should be set when the corresponding address is used. 7-bit address
or 10-bit address can be programmed in ADDRESS[9:0] in I2C_SADDR0 register by
configuring the ADDFORMAT bit in 7-bit address or 10-bit address.
The ADDM[6:0] in I2C_CTL2 register defines which bits of ADDRESS[7:1] are compared with
an incoming address byte, and which bits are ignored.
The ADDMSK2[2:0] is used to mask ADDRESS2[7:1] in I2C_SADDR1 register. For details,
refer to the description of ADDMSK2[2:0] in I2C_SADDR1 register.
When the I2C received address matches one of its enabled addresses, the ADDSEND will be
set, and an interrupt is generated if the ADDMIE bit is set. The READDR[6:0] bits in I2C_STAT
register will store the received address. And TR bit in I2C_STAT register updates after the
ADDSEND is set. The bit will let the slave to know whether to act as a transmitter or receiver.
SCL line stretching
The clock stretching is used in slave mode by default (SS=0), the SCL line can be stretched
low if necessary. The SCL will be stretched in following cases.
The SCL is stretched when the ADDSEND bit is set, and released when the ADDSEND
bit is cleared.
In slave transmitting mode, after the ADDSEND bit is cleared, the SCL will be stretched
before the first data byte writing to the I2C_TDATA register. Or the SCL will be stretched
before the new data is written to the I2C_TDATA register after the previous data
transmission is completed.
In slave receiving mode, a new reception is completed but the data in I2C_RDATA
register has not been read.
When SBCTL=1 and RELOAD=1, after the transfer of the last byte, TCR is set. Before
the TCR is cleared, the SCL will be stretched.
After SCL falling edge detection, the I2C stretches SCL low during
[(1) x (PSC+1) + 1] x tI2CCLK.
The clock stretching can be disabled by setting the SS bit in I2C_CTL0 register (SS=1). The
SCL will not be stretched in following cases.
The SCL will be not stretched while the ADDSEND is set.