GD32A50x User Manual
517
Working mode
Action
Slave receiver mode
ACK control
SMBus mode
PEC generation/checking
The number of bytes to be transferred is configured by BYTENUM[7:0] in I2C_CTL1 register.
If BYTENUM is greater than 255, or in slave byte control mode, the reload mode must be
enabled by setting the RELOAD bit in I2C_CTL1 register. In reload mode, when BYTENUM
counts to 0, the TCR bit will be set, and an interrupt will be generated if TCIE is set. Once the
TCR flag is set, SCL is stretched. The TCR bit is cleared by writing a non-zero number in
BYTENUM.
Note:
The reload mode must be disabled after the last reloading of BYTENUM[7:0].
The reload mode must be disabled when the automatic end mode is enabled. In automatic
end mode, the master will send a STOP signal automatically when the BYTENUM[7:0] counts
to 0.
When reload mode and automatic end mode are disabled, the I2C communication process
needs to be terminated by software. If the number of bytes in BYTENUM[7:0] has been
transferred, the STOP bit should be set by software to generate a STOP signal, and then TC
flag must be cleared.
20.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