Before enabling the I2C controller, perform the following steps:
- Enable the functional and interface clocks (see
WKUP I2C Clocks and Resets, MCU_I2C Clocks and Resets, and
I2C Clocks and Resets).
- Program the prescaler to obtain an approximately
12-MHz internal sampling clock by programming the corresponding value in the
I2C_PSC[7-0] PSC bit field. This value depends on the frequency of the
functional clock (SYS_CLK).
- Program the I2C_SCLL[7-0] SCLL and I2C_SCLH[7-0]
SCLH bit fields to obtain a bit rate of 100 Kbps or 400 Kbps. These values
depend on the internal sampling clock frequency (see Table 12-17).
- (Optional) Program the I2C_SCLL[15-8] HSSCLL and
I2C_SCLH[15-8] HSSCLH bit fields to obtain a bit rate of 400 Kbps or 3.4 Mbps
(for the second phase of HS mode). These values depend on the internal sampling
clock frequency (see Table 12-17).
- Configure the Own Address of the I2C controller
by storing it in the I2C_OA register. Up to four Own Addresses can be programmed
in the I2C_OA and I2C_OAx registers (where x = 1, 2, 3) for each I2C controller.
Note:
For a 10-bit address, set
the corresponding expand Own Address bit in the I2C_CON register.
- Set the TX threshold (in transmitter mode) and
the RX threshold (in receiver mode) by setting the I2C_BUF[5-0] TXTRSH bit field
to (TX threshold – 1) and the I2C_BUF[13-8] RXTRSH bit field to (RX threshold –
1), where the TX and RX thresholds are greater than or equal to 1.
- Take the I2C controller out of reset by setting
the I2C_CON[15] I2C_EN bit to 1.