![GigaDevice Semiconductor GD32E23 Series Скачать руководство пользователя страница 472](http://html.mh-extra.com/html/gigadevice-semiconductor/gd32e23-series/gd32e23-series_user-manual_2225794472.webp)
GD32E23x User Manual
472
, the following software procedure should be followed if users wish to transmit data in
slave transmitter mode:
1.
First of all, enable I2C peripheral clock as well as configure clock related registers in
I2C_CTL1 to make sure correct I2C timing. After enabled and configured, I2C operates
in its default slave state and waits for START signal followed by address on I2C bus.
2.
After receiving a START signal followed by a matched address, either in 7-bit format or
in 10-bit format, the I2C hardware sets the ADDSEND bit in I2C_STAT0 register, which
should be monitored by software either by polling or interrupt. After that, software should
read I2C_STAT0 and then I2C_STAT1 to clear ADDSEND bit. If 10-bit addressing
format is selected, the I2C master should then send a repeated START signal followed
by a header to the I2C bus. The slave sets ADDSEND bit again after it detects the
repeated START signal and the following header. The ADDSEND bit must be cleared by
software again by reading I2C_STAT0 and then I2C_STAT1.
3.
Now I2C enters data transmission stage and hardware sets TBE bit because both the
shift register and data register I2C_DATA are empty. Once TBE is set, software should
write the first byte of data to I2C_DATA register, TBE is not cleared in this case because
the byte written in I2C_DATA is moved to the internal shift register immediately. I2C
begins to transmit data to I2C bus as soon as the shift register is not empty.
4.
During the transmission of the first byte, software can write the second byte to
I2C_DATA, and this time TBE is cleared because neither I2C_DATA nor shift register is
empty.
5.
After the transmission of the first byte, the TBE bit will be set, the software can write the
third byte to the I2C_DATA register and TBE is cleared. After this, any time TBE is set,
software can write a byte to I2C_DATA as long as there is still data to be transmitted.
6.
During the transmission of the second last byte, software writes the last data to
I2C_DATA to clear the TBE flag and doesn’t care TBE anymore. So TBE will be set after
the byte’s transmission and not cleared until a STOP signal.
7.
I2C master doesn’t acknowledge to the last byte according to the I2C protocol, so after
sending the last byte, I2C slave will wait for the STOP signal on I2C bus and sets AERR
(Acknowledge Error) bit to notify software that the transmission completes. Software
clears AERR bit by writing 0 to it.