USCI I2C Module (Chapter Excerpt from Msp430x5xx Family, SLAU208)
Total Page:16
File Type:pdf, Size:1020Kb
Chapter Excerpt from SLAU208 Chapter 1 SLAU412F–August 2012–Revised March 2018 Universal Serial Communication Interface – I2C Mode NOTE: This chapter is an excerpt from the MSP430x5xx and MSP430x6xx Family User's Guide. The most recent version of the full user's guide is available here: http://www.ti.com/lit/pdf/slau208. The universal serial communication interface (USCI) supports multiple serial communication modes with one hardware module. This chapter discusses the operation of the I2C mode. Topic ........................................................................................................................... Page 1.1 Universal Serial Communication Interface (USCI) Overview ...................................... 2 1.2 USCI Introduction – I2C Mode ................................................................................ 3 1.3 USCI Operation – I2C Mode ................................................................................... 4 1.4 USCI_B I2C Mode Registers ................................................................................ 23 SLAU412F–August 2012–Revised March 2018 Universal Serial Communication Interface – I2C Mode 1 Submit Documentation Feedback Copyright © 2012–2018, Texas Instruments Incorporated Chapter Excerpt from SLAU208 Universal Serial Communication Interface (USCI) Overview www.ti.com 1.1 Universal Serial Communication Interface (USCI) Overview The USCI modules support multiple serial communication modes. Different USCI modules support different modes. Each different USCI module is named with a different letter. For example, USCI_A is different from USCI_B, etc. If more than one identical USCI module is implemented on one device, those modules are named with incrementing numbers. For example, if one device has two USCI_A modules, they are named USCI_A0 and USCI_A1. See the device-specific data sheet to determine which USCI modules, if any, are implemented on each device. USCI_Ax modules support: • UART mode • Pulse shaping for IrDA communications • Automatic baud-rate detection for LIN communications • SPI mode USCI_Bx modules support: • I2C mode • SPI mode 2 Universal Serial Communication Interface – I2C Mode SLAU412F–August 2012–Revised March 2018 Submit Documentation Feedback Copyright © 2012–2018, Texas Instruments Incorporated Chapter Excerpt from SLAU208 www.ti.com USCI Introduction – I2C Mode 1.2 USCI Introduction – I2C Mode In I2C mode, the USCI module provides an interface between the device and I2C-compatible devices connected by the two-wire I2C serial bus. External components attached to the I2C bus serially transmit and/or receive serial data to/from the USCI module through the 2-wire I2C interface. The I2C mode features include: • Compliance to the Philips Semiconductor I2C specification v2.1 • 7-bit and 10-bit device addressing modes • General call • START/RESTART/STOP • Multi-master transmitter/receiver mode • Slave receiver/transmitter mode • Standard mode up to 100 kbps and fast mode up to 400 kbps support • Programmable UCxCLK frequency in master mode • Designed for low power • Slave receiver START detection for auto wake up from LPMx modes (wake up from LPMx.5 is not supported) • Slave operation in LPM4 Figure 1-1 shows the USCI when configured in I2C mode. SLAU412F–August 2012–Revised March 2018 Universal Serial Communication Interface – I2C Mode 3 Submit Documentation Feedback Copyright © 2012–2018, Texas Instruments Incorporated Chapter Excerpt from SLAU208 USCI Operation – I2C Mode www.ti.com UCA10 UCGCEN Own Address UC1OA UCxSDA Receive Shift Register Receive Buffer UC1RXBUF I2C State Machine Transmit Buffer UC 1TXBUF Transmit Shift Register Slave Address UC1SA UCSLA10 UCxSCL UCSSELx Bit Clock Generator UCxBRx UC1CLK 00 16 ACLK 01 UCMST Prescaler/Divider SMCLK 10 BRCLK SMCLK 11 Figure 1-1. USCI Block Diagram – I2C Mode 1.3 USCI Operation – I2C Mode The I2C mode supports any slave or master I2C-compatible device. Figure 1-2 shows an example of an I2C bus. Each I2C device is recognized by a unique address and can operate as either a transmitter or a receiver. A device connected to the I2C bus can be considered as the master or the slave when performing data transfers. A master initiates a data transfer and generates the clock signal SCL. Any device addressed by a master is considered a slave. I2C data is communicated using the serial data (SDA) pin and the serial clock (SCL) pin. Both SDA and SCL are bidirectional and must be connected to a positive supply voltage using a pullup resistor. 4 Universal Serial Communication Interface – I2C Mode SLAU412F–August 2012–Revised March 2018 Submit Documentation Feedback Copyright © 2012–2018, Texas Instruments Incorporated Chapter Excerpt from SLAU208 www.ti.com USCI Operation – I2C Mode VCC MSP430 Device A Serial Data (SDA) Serial Clock (SCL) Device B Device C Figure 1-2. I2C Bus Connection Diagram NOTE: SDA and SCL levels The SDA and SCL pins must not be pulled up above the device VCC level. 1.3.1 USCI Initialization and Reset The USCI is reset by a PUC or by setting the UCSWRST bit. After a PUC, the UCSWRST bit is automatically set, keeping the USCI in a reset condition. To select I2C operation, the UCMODEx bits must be set to 11b. After module initialization, it is ready for transmit or receive operation. Clear UCSWRST to release the USCI for operation. To avoid unpredictable behavior, configure or reconfigure the USCI module only when UCSWRST is set. Setting UCSWRST in I2C mode has the following effects: • I2C communication stops. • SDA and SCL are high impedance. • UCBxI2CSTAT, bits 6–0 are cleared. • Registers UCBxIE and UCBxIFG are cleared. • All other bits and register remain unchanged. NOTE: Initializing or reconfiguring the USCI module The recommended USCI initialization/reconfiguration process is: 1. Set UCSWRST (BIS.B #UCSWRST,&UCxCTL1). 2. Initialize all USCI registers with UCSWRST = 1. 3. Configure ports. 4. Clear UCSWRST through software (BIC.B #UCSWRST,&UCxCTL1). 5. Enable interrupts (optional). 1.3.2 I2C Serial Data One clock pulse is generated by the master device for each data bit transferred. The I2C mode operates with byte data. Data is transferred MSB first as shown in Figure 1-3. The first byte after a START condition consists of a 7-bit slave address and the R/W bit. When R/W = 0, the master transmits data to a slave. When R/W = 1, the master receives data from a slave. The ACK bit is sent from the receiver after each byte on the ninth SCL clock. SLAU412F–August 2012–Revised March 2018 Universal Serial Communication Interface – I2C Mode 5 Submit Documentation Feedback Copyright © 2012–2018, Texas Instruments Incorporated Chapter Excerpt from SLAU208 USCI Operation – I2C Mode www.ti.com SDA MSB Acknowledgement Acknowledgement Signal From Receiver Signal From Receiver SCL START 1 2 7 8 9 1 2 8 9 STOP Condition (S) R/W ACK ACK Condition (P) Figure 1-3. I2C Module Data Transfer START and STOP conditions are generated by the master and are shown in Figure 1-3. A START condition is a high-to-low transition on the SDA line while SCL is high. A STOP condition is a low-to-high transition on the SDA line while SCL is high. The bus busy bit, UCBBUSY, is set after a START and cleared after a STOP. Data on SDA must be stable during the high period of SCL (see Figure 1-4). The high and low state of SDA can only change when SCL is low, otherwise START or STOP conditions are generated. Data Line Stable Data SDA SCL Change of Data Allowed Figure 1-4. Bit Transfer on I2C Bus 6 Universal Serial Communication Interface – I2C Mode SLAU412F–August 2012–Revised March 2018 Submit Documentation Feedback Copyright © 2012–2018, Texas Instruments Incorporated Chapter Excerpt from SLAU208 www.ti.com USCI Operation – I2C Mode 1.3.3 I2C Addressing Modes The I2C mode supports 7-bit and 10-bit addressing modes. 1.3.3.1 7-Bit Addressing In the 7-bit addressing format (see Figure 1-5), the first byte is the 7-bit slave address and the R/W bit. The ACK bit is sent from the receiver after each byte. 17 1 18 18 1 1 S Slave Address R/W ACK Data ACK Data ACK P Figure 1-5. I2C Module 7-Bit Addressing Format 1.3.3.2 10-Bit Addressing In the 10-bit addressing format (see Figure 1-6), the first byte is made up of 11110b plus the two MSBs of the 10-bit slave address and the R/W bit. The ACK bit is sent from the receiver after each byte. The next byte is the remaining eight bits of the 10-bit slave address, followed by the ACK bit and the 8-bit data. See I2C Slave 10-bit Addressing Mode and I2C Master 10-bit Addressing Mode for details how to use the 10- bit addressing mode with the USCI module. 1 7 1 1 8 1 8 1 1 S Slave Address 1st byte R/W ACK Slave Address 2nd byte ACK Data ACK P 1 1 1 1 0 X X Figure 1-6. I2C Module 10-Bit Addressing Format 1.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 1-7. 1 7 1 18 1 17 1 18 1 1 S Slave Address R/W ACK Data ACK S Slave Address R/W ACK Data ACK P 1 Any 1 Any Number Number Figure 1-7. I2C Module Addressing Format With Repeated START Condition SLAU412F–August 2012–Revised March 2018 Universal Serial Communication Interface – I2C Mode 7 Submit Documentation Feedback Copyright © 2012–2018, Texas Instruments Incorporated Chapter Excerpt from SLAU208 USCI Operation – I2C Mode www.ti.com 1.3.4 I2C Module Operating Modes In I2C mode, the USCI module can operate in master transmitter, master receiver, slave transmitter, or slave receiver mode.