1
7
8
7
8
1
1
1
1
1
1
1
1
S
Slave Address
R/W ACK
Data
ACK
S
Slave Address
ACK
Data
ACK
P
1
Any
Number
1
Any Number
R/W
S
1
Slave Address 1st byte
7
Slave Address 2nd byte
ACK
R/W
1
1
8
ACK
1
Data
8
ACK
1
P
1
1
1
1
1
0
X
X
eUSCI_B Operation – I
2
C Mode
826
SLAU367P – October 2012 – Revised April 2020
Copyright © 2012–2020, Texas Instruments Incorporated
Enhanced Universal Serial Communication Interface (eUSCI) – I
2
C Mode
Figure 32-6. I
2
C Module 10-Bit Addressing Format
32.3.3.3 Repeated Start Conditions
The direction of data flow on SDA can be changed by the master, without first stopping a transfer, by
issuing a repeated START condition. This is called a RESTART. After a RESTART is issued, the slave
address is again sent out with the new data direction specified by the R/W bit. The RESTART condition is
shown in
Figure 32-7. I
2
C Module Addressing Format With Repeated START Condition
32.3.4 I
2
C Quick Setup
This section gives a quick introduction into the operation of the eUSCI_B in I2C mode. The basic steps to
start communication are described and shown as a software example. More detailed information about the
possible configurations and details can be found in
The latest code examples can be found on the MSP430 web under "Code Examples".
To set up the eUSCI_B as a master transmitter that transmits to a slave with the address 0x12h, only a
few steps are needed (see
).
Example 32-1. Master TX With 7-Bit Address
UCBxCTL1 |= UCSWRST;
// put eUSCI_B in reset state
UCBxCTLW0 |= UC UCMST; // I2C master mode
UCBxBRW = 0x0008;
// baud rate = SMCLK / 8
UCBxCTLW1 = UCASTP_2;
// automatic STOP assertion
UCBxTBCNT = 0x07;
// TX 7 bytes of data
UCBxI2CSA = 0x0012;
// address slave is 12hex
P2SEL |= 0x03;
// configure I2C pins (device specific)
UCBxCTL1 &= ^UCSWRST;
// eUSCI_B in operational state
UCBxIE |= UCTXIE;
// enable TX-interrupt
GIE;
// general interrupt enable
...
// inside the eUSCI_B TX interrupt service routine
UCBxTXBUF = 0x77;
// fill TX buffer
As shown in the code example, all configurations must be done while UCSWRST is set. To select the I
2
C
operation of the eUSCI_B, UCMODE must be set accordingly. The baud rate of the transmission is set by
writing the correct divider in the UCBxBRW register. The default clock selected is SMCLK. How many
bytes are transmitted in one frame is controlled by the byte counter threshold register UCBxTBCNT
together with the UCASTPx bits.
The slave address to send to is specified in the UCBxI2CSA register. Finally, the ports must be
configured. This step is device dependent; see the data sheet for the pins that must be used.
Each byte that is to be transmitted must be written to the UCBxTXBUF inside the interrupt service routine.
The recommended structure of the interrupt service routine can be found in