GD32W51x User Manual
640
Figure 19-13. I2C initialization in slave mode
I2CEN=0
Configure DNF[3:0] in I2C_CTL0
START
Configure PSC[3:0], SDADELY[3:0],
SCLDELY[3:0] in I2C_TIMING
Configure SS in I2C_CTL0
I2CEN=1
FINISH
Clear ADDRESSEN in I2C_SADDR0
Clear ADDRESS2EN in I2C_SADDR1
Configure ADDRESS[9:0], ADDFORMAT and
ADDRESSEN in I2C_SADDR0,
ADDRESS2[7:1], ADDMSK2[2:0] and
ADDRESS2EN in I2C_SADDR1, ADDM[6:0] in
I2C_CTL2
Configure SBCTL in I2C_CTL0
Slave transmitter
When the I2C_TDATA register is empty, the TI bit in I2C_STAT register will be set. If the TIE
bit in I2C_CTL0 register is set, an interrupt will be generated. The NACK bit in I2C_STAT
register will be set when a NACK is received. And an interrupt is generated if the NACKIE bit
is set in the I2C_CTL0 register. The TI bit in I2C_STAT register will not be set when a NACK
is received.
The STPDET bit in I2C_STAT register will be set when a STOP is received. If the STPDETIE
in I2C_CTL0 register is set, an interrupt will be generated.
When SBCTL is 0, if ADDSEND=1, and the TBE bit in I2C_STAT register is 0, the data in
I2C_TDATA register can be chosed to be transmitted or flushed. The data is flushed by setting
the TBE bit.
When SBCTL=1, the slave works in slave byte control mode, the BYTENUM[7:0] must be
configured in the ADDSEND interrupt service routine. And the number of TI events is equal
to the value of BYTENUM[7:0].