![GigaDevice Semiconductor GD32E23 Series Скачать руководство пользователя страница 476](http://html.mh-extra.com/html/gigadevice-semiconductor/gd32e23-series/gd32e23-series_user-manual_2225794476.webp)
GD32E23x User Manual
476
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 a STOP signal 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
register and enters master mode. Now software should clear the SBSEND bit by
reading I2C_STAT0 and then writing a 7-bit address or header of a 10-bit address to
I2C_DATA. I2C begins to send address or header to I2C bus as soon as SBSEND bit is
cleared. If the address which has been sent is header of a 10-bit address, the hardware
sets ADD10SEND bit after sending header and software should clear the ADD10SEND
bit by reading I2C_STAT0 and writing 10-bit lower address to I2C_DATA.
4.
After the 7-bit or 10-bit address has been sent, the I2C hardware sets the ADDSEND bit
and software should clear the ADDSEND bit by reading I2C_STAT0 and then
I2C_STAT1. If the address is in 10-bit format, software should then set START bit again
to generate a repeated START signal on I2C bus and SBSEND is set after the repeated
START is sent out. Software should clear the SBSEND bit by reading I2C_STAT0 and
writing header to I2C_DATA. Then the header is sent out to I2C bus, and ADDSEND is
set again. Software should again clear ADDSEND by reading I2C_STAT0 and then
I2C_STAT1.
5.
As soon as the first byte is received, RBNE is set by hardware. Software now can read
the first byte from I2C_DATA and RBNE is cleared as well.
6.
Any time RBNE is set, software can read a byte from I2C_DATA.
7.
After the second last byte (N-1) is received, the software should clear ACKEN bit and
set STOP bit. These actions should complete before the end of the last byte’s receiving
to ensure that NACK will be sent for the last byte.
8.
After the last byte is received, RBNE is set. Software reads the last byte. Since ACKEN
has been cleared in the previous step,
I2C doesn’t send ACK for the last byte and it
generates a STOP signal after the transmission of the last byte.
The above steps require byte number N>1. If N=1, Step 7 should be performed after Step 4
and completed before the end of the single byte
’
s receiving.