Nations Technologies Inc.
Tel
:
+86-755-86309900
:
Address: Nations Tower, #109 Baoshen Road, Hi-tech Park North.
Nanshan District, Shenzhen, 518057, P.R.China
428
/
631
I2C data communication flow
Each I2C device is identified by a unique address. According to the device function, they can be either a transmitter
or a receiver.
The I2C host is responsible for generating the start bit and the end bit in order to start and end a transmission. And is
responsible for generating the SCL clock.
The I2C module supports 7-bit and 10-bit addresses, and the user can configure the address of the I2C slave through
software. After the I2C slave detects the start bit on the I2C bus, it starts to receive the address from the bus, and
compares the received address with its own address. Once the two addresses are matched, the I2C slave will send an
acknowledgement (ACK) and respond to subsequent commands on the bus: send or receive the requested data. In
addition, if the software opens a broadcast call, the I2C slave always sends a confirmation response to a broadcast
address (0x00).
Data and address are transmitted in 8-bit width, with the most significant bit first. The 1 or 2 bytes following the start
condition is the address (1 byte in 7-bit mode, 2 bytes in 10-bit mode). The address is only sent in master mode.
During the 9th clock period after 8 clocks of a byte transmission, the receiver must send back an acknowledge bit
(ACK) to the transmitter, as shown in the Figure 21-2 I2C bus protocol.
Software can enable or disable acknowledgement (ACK), and can set the I2C interface address (7-bit, 10-bit
address or general call address).
I2C slave transmission mode
In slave mode, the transmission reception flag bit (I2C_STS2.TRF) indicates whether it is currently in receiver mode
or transmission mode. When sending data to I2C bus in transmission mode, the software should follow the following
steps:
1
、
First, enable I2C peripheral clock and configure the clock related register in I2C_CTRL1, ensuring the correct
I2C timing. After these two steps are completed, I2C runs in slave mode, waiting for receiving start bit and
address.
2
、
I2C slave receives a start bit first, and then receives a matching 7-bit or 10-bit address. I2C hardware will set the
I2C_STS1.ADDRF(received address and matched its own address). The software should monitor this bit
regularly or have an interrupt to monitor this bit. After this bit is set, the software reads I2C_STS1 register and
then read I2C_STS2 register to clear the I2C_STS1.ADDRF bit. If the address is in 10 bit format, the I2C master
should then generate a START and send an address header to the I2C bus. After detecting START and the
following address header, the slave will continue to set I2C_STS1.ADDRF bit. The software continues to read
I2C_STS1 register and read I2C_STS2 register to clear the I2C_STS1.ADDRF bit a second time.
3
、
I2C enters the data sending state, and now shift register and data register I2C_DAT are all empty, so the hardware
will set the I2C_STS1.TXDATE(send data empty). At this time, the software can write the first byte data to
I2C_DAT register, however, because the byte of the I2C_DAT register is immediately moved into the internal
shift register, the I2C_STS1.TXDATE bit is not cleared to zero. When the shift register is not empty, I2C starts
to send data to I2C bus.
4
、
During the sending of the first byte, the software writes the second byte to I2C_DAT, neither the I2C_DAT
register nor the shift register is empty. The I2C_STS1.TXDATE bit is cleared to 0.