![GigaDevice Semiconductor GD32F20 Series User Manual Download Page 522](http://html.mh-extra.com/html/gigadevice-semiconductor/gd32f20-series/gd32f20-series_user-manual_2225801522.webp)
GD32F20x User Manual
522
Master Receiver
Slave Transmitter
Slave Receiver
I2C
block supports all of the four I2C modes. After system reset, it works in slave mode. If it’s
programmed by software and finished sending a START condition on I2C bus, it changes into
master mode. The I2C changes back to slave mode after it’s programmed by software and
finished sending a STOP condition on I2C bus.
Programming model in slave transmitting mode
As is shown in
Figure 20-9. Programming model for slave transmitting
, the following
software procedure should be followed if users wish to make transaction in slave transmitter
mode:
1.
First of all, software should 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 condition followed by address
on I2C bus.
2.
After receiving a START condition 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(Sr) condition followed
by a header to the I2C bus. The slave sets ADDSEND bit again after it detects the
repeated START(Sr) condition and the following header. Software needs to clear the
ADDSEND bit 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 write byte 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 first byte’s transmission, software can write the second byte to I2C_DATA, at
which time the TBE bit is cleared 0, because neither I2C_DATA nor shift register is empty.
5.
Any time TBE is set, software can write a byte to I2C_DATA as long as there are still data
to be transmitted.
6.
During the last
second byte’s transmission, software write 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 condition.
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 condition on I2C bus and sets
AERR (Acknowledge
Error
) bit to notify software that transmission completes. Software
Summary of Contents for GD32F20 Series
Page 191: ...GD32F20x User Manual 191 Bits Fields Descriptions 31 0 TRNDATA 31 0 32 Bit Random data ...
Page 290: ...GD32F20x User Manual 290 conversion is ongoing ...
Page 325: ...GD32F20x User Manual 325 15 0 ALRM 15 0 RTC alarm value low ...
Page 385: ...GD32F20x User Manual 385 ...
Page 523: ...GD32F20x User Manual 523 clears AERR bit by writing 0 to it ...