GD32F403xx User Manual
433
clears AERR bit by writing 0 to it.
Figure 18-9. Programming model for slave transmitting mode (10-bit address mode)
IDLE
Master generates START
condition
Master sends Address
Slave sends Acknowledge
Master generates repeated
START condition
Master sends header
Slave sends Acknowledge
SCL stretched by slave
Slave sends DATA(1)
Master sends Acknowledge
……
(
Data transmission
)
Slave sends DATA(N-2)
Master sends Acknowledge
Slave sends DATA(N)
Master DON'T send Ack
Master generates STOP
condition
1) Software initialization
Set ADDSEND
2) Clear ADDSEND
Set ADDSEND
2) Clear ADDSEND
Set TBE
Set TBE
Set TBE
Set AERR
Clear TBE
3) Write DATA(1) to TRB
Write DATA(x) to TRB
Set TBE
4) Write DATA(2) to TRB
5) Write DATA(3) to TRB
6)Write DATA(N) to TRB
Slave sends DATA(N-1)
Master sends Acknowledge
Set TBE
7) Clear AERR
I2C Line State
Hardware Action
Software Flow
Master sends Header
Slave sends Acknowledge
Programming model in slave receiving mode
Figure 18-10. Programming model for slave receiving (10-bit address
, the following software procedure should be followed if users wish to receive data in
slave receiver 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 7-bit or 10-bit address, the I2C
hardware sets the ADDSEND bit in I2C status register 0, 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. The I2C begins to receive data on I2C bus as