GD32W51x User Manual
652
BYTENUM=0x1 and PECTRANS bit is set at the same time, the contents of the I2C_PEC
register are automatically transferred. If the automatic end mode is selected (AUTOEND=1),
the SMBus master automatically sends the STOP condition after the PEC byte. If the
automatic end mode is not selected (AUTOEND=0), the SMBus master can send a RESTART
condition after the PEC. The I2C_PEC register content will be sent after BYTENUM -1 bytes,
and the TC flag will be set after PEC is sent, then the SCL line is stretched low. The RESTART
must be set in the TC interrupt routine.
When used as slave receiver, in order to allow PEC checking at the end of the number of
bytes transmitted, SBCTL must be set. To configure ack control for each byte, the RELOAD
must be set to enable the RELOAD mode. In order to check the PEC byte, it is necessary to
clear the RELOAD bit and set PECTRANS bit. After receiving BYTENUM-1 data, the next
received byte will be compared with the contents of the I2C_PEC register. If the comparison
does not match, the NACK is automatically generated; if the comparison matches, the ACK
is automatically generated, regardless of the ACK bit value. When PEC byte is received, it is
also copied into the I2C_RDATA register like other data, and RBNE flag will be set. If the
ERRIE bit in I2C_CTL0 register is 1, when PEC does not match, the PECERR flag will be set
and the interrupt will be generated. If ACK control is not required, then PECTRANS can be
set to 1 and BYTENUM can be programmed according to the number of bytes to be received.
Note:
After the RELOAD bit is set, the PECTRANS cannot be changed.
Figure 19-22. SMBus Master Transmitter and Slave Receiver communication flow
Start Slave address
ACK
DATA0
ACK
DATA N-1
ACK
Stop
……
data transfer (N+1 bytes)
From master to slave
From slave to master
W(0)
PEC
ACK
SMBus Master Receiver and Slave Transmitter
If the SMBus master is required to receive PEC at the end of bytes transfer, automatic end
mode can be chose (AUTOEND=1). Before sending a START condition on the bus,
PECTRANS bit must be set and slave addresses must be programmed. After receiving
BYTENUM-1 data, the next received byte will be compared with the contents of the I2C_PEC
register automatically. A NACK is respond to the PEC byte before STOP condition.
If the SMBus master receiver is required to generate a RESTART signal after receiving PEC
byte, the software mode (AUTOEND = 0) must be selected. Before sending a START signal
to the bus, PECTRANS bit must be set and slave addresses must be programmed. After
receiving BYTENUM-1 data, the next received byte will be compared with the contents of the
I2C_PEC register automatically. The TC flag will be set after PEC is sent, then the SCL line
is stretched low. The RESTART can be set in the TC interrupt routine.
When used as slave transmitter, in order to allow PEC transmission at the end of
BYTENUM[7:0] bytes, SBCTL must be set. If PECTRANS bit is set, the number of bytes in
BYTENUM[7:0] contains PEC byte. In this case, if the number of bytes requested by the