Inter-Integrated Circuit (I2C) Interface
310 October 8, 2006
Preliminary
Table 14-1 gives examples of Timer period, system clock, and speed mode (Standard or Fast).
14.3 Initialization and Configuration
The following example shows how to configure the I
2
C module to send a single byte as a master.
This assumes the system clock is 20 MHz.
1. Enable the I
2
C clock by writing a value of 0x00001000 to the RCGC1 register in the System
Control module.
2. In the GPIO module, enable the appropriate pins for their alternate function using the
GPIOAFSEL register. Also, be sure to enable the same pins for Open Drain operation.
3. Initialize the I
2
C Master by writing the I2CMCR register with a value of 0x00000020.
4. Set the desired SCL clock speed of 100 Kbps by writing the I2CMTPR register with th e 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 determined by the following equation:
TPR = (System Clock / (2 * (SCL_LP + SCL_HP) * SCL_CLK)) - 1;
TPR = (20MHz / (2 * (6 + 4) * 100000)) - 1;
TPR = 9
Writ e the I2CMTPR register with the value of 0x00000009.
5. Specify the slave address of the master and that the next operation will be a Send by writing
the I2CMSA register with a value of 0x00000076. This sets the slave address to 0x3B.
6. Place data (byte) to be sent in the data register by writing the I2CMDR register with the
desired data.
7. Initiate a single byte send of the data from Master to Slave by writing the I2CMCS register with
a value of 0x00000007 (STOP, START, RUN).
8. Wait until the transmission completes by polling the I2CMCS register’s BUSBSY bit until it has
been cleared.
Table 14-1. Examples of I
2
C Master Timer Period versus Speed Mode
System
Clock
Timer
Period
Standard
Mode
Timer
Period
Fast
Mode
4 Mhz 0x01 100 Kbps - -
6 Mhz 0x02 100 Kbps - -
12.5 Mh z 0 x0 6 89 Kbp s 0x0 1 312 Kbps
16.7 Mh z 0 x0 8 93 Kbp s 0x0 2 278 Kbps
20 M hz 0x09 100 Kbps 0x02 333 Kbps
25 Mhz 0x0C 96.2 Kbps 0x03 312 Kbps
33Mhz 0x10 97.1 Kbps 0x04 330 Kbps
40Mhz 0x13 100 Kbps 0x04 400 Kbps
50Mhz 0x18 100 Kbps 0x06 357 Kbps