The following example shows how to configure the I2C module to transmit a
single byte as a controller, assuming that the system clock is 48 MHz.
- Enable the serial power domain
and enable the I2C module in CLKCTL by setting the
CLKCTL.CLKENSET0[6] I2C0 bit.
- Configure the IOC module to route
the SDA and SCL signals from I/Os to the I2C and configure the pins
for open-drain. See Chapter 387 for more information.
- Initialize the I2C
controller by writing the I2C:CCR register with a value of 0x0010
- Set the desired SCL clock speed
of 100 kbps by writing the I2C.CTPR register with the correct value. The value
written to the I2C.CTPR register represents the number of system clock periods
in one SCL clock period. The TPR value is determined by Equation 12,Equation 13, and Equation 14
Equation 12. TPR = [CLKSVT / (2 × (SCL_LP + SCL_HP) ×
SCL_FREQ)] – 1
Equation 13. TPR = [48 MHz / (2 × (6 + 4) × 100000)]
– 1
Equation 14. TPR = 23
Write the I2C:CTPR register with the
value of 0x0000 0017.
- Specify the target address of
the controller and that the next operation is a transmit by writing the I2C.CSA
register with a value of 0x0000 0076, which sets the target address to
0x3B.
- Place data (byte) to be
transmitted in the data register by writing the I2C:CDR register with the
desired data.
- Initiate a single-byte transmit
of the data from controller to target by writing the I2C.CCTL register with a
value of 0x0000 0007 (Stop, Start, Run).
- Wait until the transmission
completes by polling the I2C.CSTAT[6] BUSBSY bit until the bit is cleared.
- Check the I2C.CSTAT[1] ERR bit
to confirm the transmit was acknowledged.