Initialization and Configuration
1333
SLAU723A – October 2017 – Revised October 2018
Copyright © 2017–2018, Texas Instruments Incorporated
Inter-Integrated Circuit (I
2
C) Interface
19.4 Initialization and Configuration
19.4.1 Configure the I
2
C Module to Transmit a Single Byte as a Master
The following example shows how to configure the I
2
C module to transmit a single byte as a master. This
assumes the system clock is 20 MHz.
1. Enable the I
2
C clock using the RCGCI2C register in the System Control module (see
2. Enable the clock to the appropriate GPIO module using the RCGCGPIO register in the System Control
module (see
). To find out which GPIO port to enable, see the device-specific data
sheet.
3. In the GPIO module, enable the appropriate pins for their alternate function using the GPIOAFSEL
register (see
). To determine which GPIOs to configure, see the device-specific data
sheet.
4. Enable the I2CSDA pin for open-drain operation. See
.
5. Configure the PMCn fields in the GPIOPCTL register to assign the I
2
C signals to the appropriate pins.
See
and the device-specific data sheet.
6. Initialize the I
2
C master by writing the I2CMCR register with a value of 0x0000.0010.
7. Set the desired SCL clock speed of 100 kbps by writing the I2CMTPR register with the correct value.
The value written to the I2CMTPR register represents the number of system clock periods in one SCL
clock period. The TPR value is calculated by using
TPR = (System Clock / (2 × ( SCL_HP) × SCL_CLK)) – 1
TPR = (20 MHz / (2 × (6 + 4) × 100000)) – 1
TPR = 9
(63)
Write the I2CMTPR register with the value of 0x0000.0009.
8. Specify the slave address of the master and that the next operation is a Transmit by writing the
I2CMSA register with a value of 0x0000.0076. This sets the slave address to 0x3B.
9. Place data (byte) to be transmitted in the data register by writing the I2CMDR register with the desired
data.
10. Initiate a single byte transmit of the data from master to slave by writing the I2CMCS register with a
value of 0x0000.0007 (STOP, START, RUN).
11. Wait until the transmission completes by polling the BUSBSY bit in the I2CMCS register until it has
been cleared.
12. Check the ERROR bit in the I2CMCS register to confirm the transmit was acknowledged.