GD32VF103 User Manual
363
Figure 17-11. Programming model for master transmitting(10-bit address mode)
IDLE
Master generates START
condition
Master sends Address
Slave sends Acknowledge
Master sends Header
Slave sends Acknowledge
SCL stretched by master
Master sends DATA(1)
Slave sends Acknowledge
……
(
Data transmission
)
Master sends DATA(N-2)
Slave sends Acknowledge
Master sends DATA(N)
Slave sends Acknowledge
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 I2C_DATA
Write DATA(x) to I2C_DATA
Set TBE
6) Write DATA(2) to I2C_DATA
7) Write DATA(3) to I2C_DATA
8)Write DATA(N) to I2C_DATA
Master sends DATA(N-1)
Slave sends Acknowledge
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 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 your application: 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, 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.