Texas Instruments CC2650DK 사용자 설명서

다운로드
페이지 1570
Initialization and Configuration
21.4 Initialization and Configuration
The following example shows how to configure the I2C module to transmit a single byte as a master. This
assumes the system clock is 24 MHz.
1. Enable the serial power domain and enable the I2C module in PRCM by writing to the
[PRCM:I2CCLKGR] register, the [PRCM:I2CCLKGS] register, or [PRCM:I2CCLKGDS] registers, or by
using 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
or by using the driverlib function
PRCMLoadSet().
2. Configure the IOC module to route the SDA and SCL signals from I/Os to the I2C module.
3. Initialize the I
2
C master by writing the [I2C_MCR] register with a value of 0x0000 0010.
4. 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
through
.
TPR = (PERDMACLK / (2 × (SCL_LP + SCL_HP) × SCL_CLK)) – 1
(7)
TPR = (24 MHz / (2 × (6 + 4) × 100000)) – 1
(8)
TPR = 11
(9)
Write the [I2C_MTPR] register with the value of 0x0000 000B.
5. 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.
6. Place data (byte) to be transmitted in the data register by writing the [I2C_MDR] register with the
desired data.
7. 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).
8. Wait until the transmission completes by polling the BUSBSY bit of the [I2C_MSTAT] register until it
BUSBSY is cleared.
9. Check the ERR bit in the [I2C_MSTAT] register to confirm the transmit was acknowledged.
21.5 I
2
C Registers
1391
SWCU117A – February 2015 – Revised March 2015
Inter-Integrated Circuit (I
2
C) Interface
Copyright © 2015, Texas Instruments Incorporated