GD32F403xx User Manual
436
Figure 18-11. Programming model for master transmitting mode (10-bit address mode)
IDLE
Master generates START
condition
Master sends Address
Slave sends ACK
Master sends Header
Slave sends ACK
SCL stretched by master
Master sends DATA(1)
Slave sends ACK
……
(
Data transmission
)
Master sends DATA(N-2)
Slave sends ACK
Master sends DATA(N)
Slave sends ACK
Master generates STOP
condition
1) Software initialization
Set ADD10SEND
4) Clear ADD10SEND
Set ADDSEND
4) Clear ADDSEND
Set TBE
Set TBE
Set TBE
Set BTC
5) Write DATA(1) to TRB
Write DATA(x) to TRB
Set TBE
6) Write DATA(2) to TRB
7) Write DATA(3) to TRB
8)Write DATA(N) to TRB
Master sends DATA(N-1)
Slave sends ACK
Set TBE
9) Set STOP
I2C Line State
Hardware Action
Software Flow
2) Set START
Set SBSEND
SCL stretched by master
3) Clear SBSEND
SCL stretched by master
SCL stretched by master
Programming model in master receiving mode
In master receiving mode, a master is responsible for generating NACK for the last byte
reception and then sending STOP a condition on I2C bus. So, special attention should be
paid to ensure the correct ending of data reception. Two solutions for master receiving are
provided here for applications: Solution A and B. Solution A requires the software’s quick
response to I2C events, while Solution B doesn’t.
Solution A
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.
Software sets START bit requesting I2C to generate a START signal on I2C bus.
3.
After sending a START signal, the I2C hardware sets the SBSEND bit in I2C_STAT0