Nations Technologies Inc.
Tel
:
+86-755-86309900
:
info@nationstech.com
Address: Nations Tower, #109 Baoshen Road, Hi-tech Park North.
Nanshan District, Shenzhen, 518057, P.R.China
433
/
631
I2C master receiving mode
In master mode, software receiving data from I2C bus should follow the following steps:
1
、
First, enable the I2C peripheral clock and configure the clock-related registers in I2C_CTRL1, in order to ensure
that the correct I2C timing is output. After enabling and configuring, I2C runs in slave mode by default, waiting
to receive the start bit and address.
2
、
When BUSY=0, set the I2C_CTRL.STARTGEN bit, and the I2C interface will generate a start condition and
switch to the master mode (I2C_STS2.MSMODE bit is set to 1).
3
、
Once the start condition is issued, the I2C hardware sets I2C_STS1.STARTBF(start bit flag) and enters the host
mode. If the I2C_CTRL2.EVTINTEN bit is set to 1, an interrupt will be generated. Then the software reads the
I2C_STS1 register and then writes a 7-bits address or a 10-bits address with an address header to the I2C_DAT
register, in order to clear the I2C_STS1.STARTBF bit. After the I2C_STS1.STARTBF bit is cleared to 0, I2C
begins to send the address or address header to the I2C bus.
In 10-bits address mode, sending a header sequence will generate the following events:
The I2C_STS1.ADDR10F bit is set to 1 by hardware, and if the I2C_CTRL2.EVTINTEN bit is set to 1, an
interrupt will be generated. Then the master device reads the STS1 register, and then writes the second byte of
address into the DAT register.
The I2C_STS1.ADDRF bit is set to 1 by hardware, and if the I2C_CTRL2.EVTINTEN bit is set to 1, an interrupt
will be generated. Then the master device reads the STS1 register and the STS2 register in sequence.
Note: In the receiver mode, the master device sends the header byte (11110xx0) firstly, then sends the lower 8
bits of the slave address, and then resends a start condition followed by the header byte (11110xx1) (where xx
represents the highest 2 digits of the 10-bits address).
In the 7-bits address mode, only one address byte needs to be sent, once the address byte is sent:
The I2C_STS1.ADDRF bit is set to 1 by hardware, and if the I2C_CTRL2.EVTINTEN bit is set to 1, an interrupt
will be generated. Then the master device waits to read the STS1 register once, and then reads the STS2 register.
Note: In the receiving mode, the master device sets the lowest bit as ‘1’ when sending the slave address.
4
、
After the 7-bits or 10-bits address is sent, the I2C hardware sets the I2C_STS1.ADDRF bit (address has been
sent) to 1. If the I2C_CTRL2.EVTINTEN bit is set to 1, an interrupt will be generated. The software clears the
I2C_STS1.ADDRF bit by reading the I2C_STS1 register and the I2C_STS2 register in sequence. If in the 10-
bit address mode, software should set the I2C_CTRL1.STARTGEN bit again to regenerate a START. After the
START is generated, the I2C_STS1.STARTBF bit will be set. The software should clear the
I2C_STS1.STARTBF bit by reading I2C_STS1 firstly and then writing the address header to I2C_DAT, and
then the address header is sent to the I2C bus, I2C_STS1.ADDRF is set to 1 again. The software should clear
the I2C_STS1.ADDRF bit again by reading I2C_STS1 and I2C_STS2 in sequence.
5
、
After sending the address and clearing the I2C_STS1.ADDRF bit, the I2C interface enters the host receiving
mode. In this mode, the I2C interface receives data bytes from the SDA line and sends them to the DAT register
through the internal shift register. Once the first byte is received, the hardware will set the
I2C_STS1.RXDATNE bit (not empty flag bit of received data) to 1, and if the I2C_CTRL1.ACKEN bit is set
to 1, an acknowledge pulse will be sent. At this time, the software can read the first byte from the I2C_DAT
register, and then the I2C_STS1.RXDATNE bit is cleared to 0. After that, as long as I2C_STS1.RXDATNE is