The following example shows how to configure the I2C module to transmit a single byte as a master, assuming that the system clock is 24 MHz.
- Enable the serial power domain and enable the I2C module in PRCM by writing to the PRCM:I2CCLKGR register, the PRCM:I2CCLKGS register, the PRCM:I2CCLKGDS register, or by using the following driver library functions:
PRCMPeripheralRunEnabe(uint32_t)
PRCMPeripheralSleepEnable(uint32_t)
PRCMPeripheralDeepSLeepEnable(uint32_t)
and loading the setting to clock controller by writing to the PRCM:CLKLOADCTL register
or by using the driverlib function PRCMLoadSet().
- Configure the IOC module to route the SDA and SCL signals from I/Os to the I2C module.
- Initialize the I2C master by writing the I2C:MCR register with a value of 0x0000 0010.
- Set the desired SCL clock speed of 100 kbps by writing the I2C:MTPR register with the correct value. The value written to the I2C:MTPR register represents the number of system clock periods in one SCL clock period. The TPR value is determined by Equation 11, Equation 12, and Equation 13.
Equation 11. TPR = [PERDMACLK / (2 × (SCL_LP + SCL_HP) × SCL_CLK)] – 1
Equation 12. TPR = [24 MHz / (2 × (6 + 4) × 100000)] – 1
Equation 13. TPR = 11
Write the I2C:MTPR register with the value of 0x0000 000B.
- Specify the slave address of the master and that the next operation is a transmit by writing the I2C:MSA register with a value of 0x0000 0076, which sets the slave address to 0x3B.
- Place data (byte) to be transmitted in the data register by writing the I2C:MDR register with the desired data.
- Initiate a single-byte transmit of the data from master to slave by writing the I2C:MCTRL register with a value of 0x0000 0007 (Stop, Start, Run).
- Wait until the transmission completes by polling the I2C:MSTAT BUSBSY register bit until it is cleared.
- Check the I2C:MSTAT ERR register bit to confirm the transmit was acknowledged.