09.12.2012 Views

RM0090: Reference manual - STMicroelectronics

RM0090: Reference manual - STMicroelectronics

RM0090: Reference manual - STMicroelectronics

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>RM0090</strong> Inter-integrated circuit (I 2 C) interface<br />

Figure 241. Transfer sequence diagram for slave receiver<br />

7-bit slave receiver<br />

10-bit slave receiver<br />

1. The EV1 event stretches SCL low until the end of the corresponding software sequence.<br />

2. The EV2 event stretches SCL low if the software sequence is not completed before the end of the next byte<br />

reception.<br />

3. After checking the SR1 register content, the user should perform the complete clearing sequence for each<br />

flag found set.<br />

Thus, for ADDR and STOPF flags, the following sequence is required inside the I2C interrupt routine:<br />

READ SR1<br />

if (ADDR == 1) {READ SR1; READ SR2}<br />

if (STOPF == 1) {READ SR1; WRITE CR1}<br />

The purpose is to make sure that both ADDR and STOPF flags are cleared if both are found set.<br />

Closing slave communication<br />

After the last data byte is transferred a Stop Condition is generated by the master. The<br />

interface detects this condition and sets:<br />

● The STOPF bit and generates an interrupt if the ITEVFEN bit is set.<br />

The STOPF bit is cleared by a read of the SR1 register followed by a write to the CR1<br />

register (see Figure 241: Transfer sequence diagram for slave receiver EV4).<br />

25.3.3 I 2 C master mode<br />

S Address A Data1 A Data2 A<br />

DataN A P<br />

.....<br />

EV1 EV2 EV2 EV2 EV4<br />

S Header A Address A Data1 A<br />

DataN A P<br />

.....<br />

EV1 EV2 EV2 EV4<br />

Legend: S= Start, S r = Repeated Start, P= Stop, A= Acknowledge,<br />

EVx= Event (with interrupt if ITEVFEN=1)<br />

EV1: ADDR=1, cleared by reading SR1 followed by reading SR2<br />

EV2: RxNE=1 cleared by reading DR register.<br />

EV4: STOPF=1, cleared by reading SR1 register followed by writing to the CR1 register<br />

In Master mode, the I 2 C interface initiates a data transfer and generates the clock signal. A<br />

serial data transfer always begins with a Start condition and ends with a Stop condition.<br />

Master mode is selected as soon as the Start condition is generated on the bus with a<br />

START bit.<br />

The following is the required sequence in master mode.<br />

● Program the peripheral input clock in I2C_CR2 Register in order to generate correct<br />

timings<br />

● Configure the clock control registers<br />

● Configure the rise time register<br />

● Program the I2C_CR1 register to enable the peripheral<br />

● Set the START bit in the I2C_CR1 register to generate a Start condition<br />

The peripheral input clock frequency must be at least:<br />

● 2 MHz in Standard mode<br />

● 4 MHz in Fast mode<br />

ai18208<br />

Doc ID 018909 Rev 3 710/1416

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!