The following example shows how to
configure the I2C module to transmit a single byte as a master. This assumes the
functional clock is 20 MHz (80MHz peripherals clock is divided by 4).
- Select and configure the I2C clock using the CLKCTL and CLKDIV registers.
- Connect the SDA and SCL pins by configuring the IOMUX aperture
- Configure the SDA and SCL pins through their respective IOMUX PINCM registers as
open-drain inputs.
- Initialize the I2C Controllerby writing the CCTR register with a value of
00000000h.
- Set the desired SCL clock speed of 100 kbps by writing the CTPR register with
the correct value. The value written to the CTPR register represents the number
of functional clock periods in one SCL clock period. The TPR value is determined
by the following equation:
Equation 10.
Equation 11.
Equation 12.
- Write the CTPR register with the value of 0x00000013.
- Specify the Target address and write mode (transmit) for the next operation by
writing the CSA register with a value of 0x00000076. This sets the Target
address to 0x3B and the DIR bit to 0x0.
- Place data (byte) to be transmitted in the data register by writing the TXDATA
register with the desired data.
- Initiate a single byte transmit of the data from Controllerto Target by writing
the CCTR register with a value of 0x00010007 (BLEN=1, STOP, START,
BURSTRUN).
- Wait until the transmission completes by polling the CSR register's BUSY bit
until it has been cleared.
- Check the ERROR bit in the CSR register to confirm the transmission was
successful.