www.ti.com

Table of Contents

Application Note
UART-to-I2C Bridge Using Low-Memory MSP430™ MCUs

Jonhson He

MSP430 Applications
ABSTRACTThe universal asynchronous receiver transmitter (UART) interface and the inter-integrated circuit (I2C) interface
are two common serial communication interfaces. They both enable communication between the MSP430™
microcontroller (MCU) and another device, such as a personal computer (PC), another MCU, or a processor.
Many devices support only one or the other interface, therefore some designs require communication between
devices with these different serial protocols. This application report describe a program that can convert between
UART and I2C protocols. In this program, both hardware UART and I2C modes are used, which can support
baud rates up to 921600 and I2C clock frequencies up to 400 kHz.

Table of Contents
1 Introduction.............................................................................................................................................................................2
2 Implementation....................................................................................................................................................................... 2
3 UART Message Format...........................................................................................................................................................3
3.1 Write N Bytes to Slave Device........................................................................................................................................... 3
3.2 Read N Bytes From Slave Device......................................................................................................................................3
3.3 Repeated Start (Read After Write)..................................................................................................................................... 4
3.4 Repeated Start (Write After Write)..................................................................................................................................... 4
3.5 Write to Internal Register....................................................................................................................................................4
3.6 Read From Internal Register..............................................................................................................................................5
4 Internal Registers Available...................................................................................................................................................5
4.1 Register Summary..............................................................................................................................................................5
4.2 Baud Rate Generator (BRG)..............................................................................................................................................5
4.3 I2C Bus Clock Rates (I2CClk)............................................................................................................................................ 6
5 Performance............................................................................................................................................................................6
6 Application Examples.............................................................................................................................................................7
6.1 Test With I2C Slave Device................................................................................................................................................ 7
6.2 Read and Write EEPROM..................................................................................................................................................7
7 Reference................................................................................................................................................................................ 98 Revision History......................................................................................................................................................................9

Trademarks
MSP430™ and LaunchPad™ are trademarks of Texas Instruments.
All trademarks are the property of their respective owners.

SLAA908A – SEPTEMBER 2019 – REVISED SEPTEMBER 2021
UART-to-I2C Bridge Using Low-Memory MSP430™ MCUs
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated

1

Introduction

www.ti.com

1 Introduction
The MSP430FR2311 MCU has two eUSCI modules that can be used as a low-cost UART-to-I2C bridge(configured as an I2C master) using the UART and I2C modes. This bridge make it convenient for hardware
devices that support only UART to access I2C protocol devices for data transmission and exchange. To getstarted, download the project files and a code example that demonstrate this functionality.

2 Implementation
Figure 2-1 shows the block diagram for the UART-to-I2C bridge. The MSP-TS430PW20 target development
board was used to connect the peripherals to the MSP430FR2311 MCU. Set the jumpers as listed here:
•
•
•
•
•

Populate jumpers JP14, JP15, JP17, and JP18
Do not populate jumper JP13
Set jumper JP16 to UART
Set jumpers JP3 to JP8 all on 1-2
Set jumper JP11 on 1-3 and 2-4

These jumper settings allow the back-channel UART interface on the MSP-FET programmer and debugger tosimulate the UART device that will communicate with the bridge. At the same time, the 10k resistor is used
as a pullup on the I2C pins. To communication with an I2C device, connect the SCL pin of the I2C device toJ4.19 (P1.3) and connect the SDA pin to J4.20 (P1.2). A simple I2C slave project was implemented on an
MSP430FR2311 LaunchPad™ development kit to demonstrate the functionality of the UART-to-I2C bridge. The
UART-to- I2C bridge functions in I2C master mode.
SDA

I2C slave device
SCL

P1.2

P1.7

MSP430FR2311
P1.3

P1.6

P1.2

UART device
P1.3

NOTE: Pullup resistors are required on the I2C bus.

Figure 2-1. UART-to-I2C Bridge Block Diagram
Using a PC, open a new serial connection with a terminal program, and connect to the back-channel UART
interface on the MSP-FET by selecting the COM port called MSP Application UART1. In the terminal window,change the baud rate to 115200. To demonstrate the functionality of the UART-to-I2C bridge, enter a string ofbytes into the terminal window follow command formats and send it. It will be sent to the I2C slave device, andwhatever value was in the TX buffer of the I2C slave device will be displayed in the serial terminal.
Figure 2-2 shows the flowchart for the I2C and UART code.
When an I2C packet is received, the UCRXIFG interrupt flag is set, and the data is read from the I2C RX bufferand stored in the internal buffer (default size is 100 bytes). Next when the data is receive completed, write thisdata to UART TX buffer and send it through the UART.
When a UART packet is received, it is stored in the internal buffer (the default size is 100 bytes), and then theapplication analyzes the UART packet command format. Different steps are performed for these two command
formats: read or write data through the I2C interface, or read or write internal register data.

2

UART-to-I2C Bridge Using Low-Memory MSP430™ MCUsSLAA908A – SEPTEMBER 2019 – REVISED SEPTEMBER 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated

www.ti.com

UART Message Format

Figure 2-2. I2C and UART Code Flow

3 UART Message Format
The host initiates an I2C bus data transfer, or reads from and writes to internal registers through a series of
ASCII commands. Table 3-1 lists the supported ASCII commands and their hexadecimal value representation.
Unrecognized commands are ignored by the device.
Table 3-1. ASCII Commands
ASCII

Hex Value

FunctionS

0x53

I2C startP

0x50

I2C stopR

0x52

Read from internal register

W

0x57

Write to internal register

3.1 Write N Bytes to Slave Device
The host issues the write command by sending an S character followed by an I2C bus slave device address, thetotal number of bytes to be sent, and I2C bus data which begins with the first byte (DATA 0) and ends with thelast byte (DATA N). The frame is then terminated with a P character. Once the host issues this command, theMSP430 MCU will access the I2C bus slave device and start sending the I2C bus data bytes.
Note that the second byte sent is the I2C bus device slave address. The least significant bit (W) of this byte must
be set to 0 to indicate this is an I2C bus write command.
Host sends

Start (S)character

Slave address+ write bit (W)Number of
bytes

Data 0...

Data N

Stop (P)characterFigure 3-1. Write N Bytes to Slave Device

3.2 Read N Bytes From Slave Device
The host issues the read command by sending an S character followed by an I2C bus slave device address, andthe total number of bytes to be read from the addressed I2C bus slave. The frame is then terminated with a P
character. Once the host issues this command, the MSP430 MCU will access the I2C bus slave device, get thecorrect number of bytes from the addressed I2C bus slave, and then return the data to the host.
The second byte sent is the I2C bus device slave address. The least significant bit (R) of this byte must be set to
1 to indicate this is an I2C bus write command.

SLAA908A – SEPTEMBER 2019 – REVISED SEPTEMBER 2021
UART-to-I2C Bridge Using Low-Memory MSP430™ MCUs
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated

3

UART Message Format

www.ti.com
Host sends

Start (S)character

Slave address+ read bit (R)Number of
bytes

...

Data N

Stop (P)character

Slave responds

Data 0Figure 3-2. Read N Bytes From Slave Device

3.3 Repeated Start (Read After Write)
The bridge also supports ‘read after write’ command as specified in the I2C bus specification. This allows aread command to be sent after a write command without having to issue a STOP condition between the twocommands.
The host issues a write command as normal, then immediately issues a read command without sending a STOP
(P) character after the write command.
Host sends

Start (S)character...

Slave address+ write bit (W)Number ofbytes

Start (S)character

Data N

Data 0Slave address+ read bit (R)...

Number of
bytes

Stop (P)character

Slave responds...

Data 0

Data N

Figure 3-3. Repeated Start : Read After Write

3.4 Repeated Start (Write After Write)
The bridge also supports ‘write after write’ command as specified in the I2C bus specification. This allows awrite command to be sent after a write command without having to issue a STOP condition between the twocommands.
The host issues a write command as normal, then immediately issues a second write command without sending
a STOP (P) character after the first write command.
Host sends

Start (S)character...

Slave address+ write bit (W)Data N

Number ofbytes

Start (S)character

Data 0Slave address+ write bit (W)Number of
bytes

...
Data 0...

Data N

Stop (P)characterFigure 3-4. Repeated Start : Write After Write

3.5 Write to Internal Register
The host issues the internal register write command by sending a W character followed by the register and data
pair. Each register to be written must be followed by the data byte.
The frame is then terminated with a P character.

4

UART-to-I2C Bridge Using Low-Memory MSP430™ MCUsSLAA908A – SEPTEMBER 2019 – REVISED SEPTEMBER 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated

www.ti.com

UART Message Format
Host sends

Write register(W) character

Register 0

Data 0...

Register N

Stop (P)character

Data N

Figure 3-5. Write to Internal Register
Note
The values of the written registers are stored in the internal FRAM of the MSP430 MCU and have amemory function.

3.6 Read From Internal Register
The host issues the internal register read command by sending an R character followed by the registers to beread.
The frame is then terminated with a P character.
Host sends

Read register(R) character

Register 0

...

...

Data N

Stop (P)character

Register N

MCU responds

Data 0Figure 3-6. Read From Internal Register

4 Internal Registers Available
4.1 Register Summary
Table 4-1 lists the internal registers of the MSP430FR2311 that control this application.
Table 4-1. Internal Registers Summary
Address

Register

Bit 7

Bit 6

Bit 5

Bit 4

Bit 3

Bit 2

Bit 1

Bit 0

R/W

0x00

BRG0

bit7

bit6

bit5

bit4

bit3

bit2

bit1

bit0

R/W

0x01

BRG1

bit7

bit6

bit5

bit4

bit3

bit2

bit1

bit0

R/W

0x02

I2CClkL

bit7

bit6

bit5

bit4

bit3

bit2

bit1

bit0

R/W

0x03

I2CClkH

bit7

bit6

bit5

bit4

bit3

bit2

bit1

bit0

R/W

4.2 Baud Rate Generator (BRG)
This register sets the UART baud rate (the default is 115200). Table 4-2 lists the supported rates.
Table 4-2. UART Baud Rate
BRG

UART Baud Rate

(hex)

(dec)

0x0023354608000x004670

2304000x008A

138

1152000x0116278

57600

0x0682

1666

9600

The rate is programmed through the BRG register and the baud rate can be calculated as Equation 1.
Baud rate=

16 × 106
BRG1, BRG0(1)

SLAA908A – SEPTEMBER 2019 – REVISED SEPTEMBER 2021
UART-to-I2C Bridge Using Low-Memory MSP430™ MCUs
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated

5

Internal Registers Available

www.ti.com

Note
For the new baud rate to take effect, both BRG0 and BRG1 must be written with new values
simultaneously. The new baud rate takes effect immediately after BRG0 or BRG1 are written.

4.3 I2C Bus Clock Rates (I2CClk)
This register sets the serial clock frequency (the default is 100 kHz). Table 4-3 lists the supported serial rates.
Table 4-3. I2C Bus Clock Frequency
I2CClk
(hex)

(dec)

I2C Bus Clock
Frequency (kHz)0x002840

400

0x005080

200

0x00A0160

100

0x0140320

50

0x0280640

25

The frequency can be determined using Equation 2.
I 2C Bit Frequency=

16 × 106
I2CClkH, I2ClkL

(2)

Note
For the new bit frequency to take effect, both I2CClkH and I2CClkL must be written with new values
simultaneously. The new baud rate takes effect immediately after I2CClkH or I2CClkL are written.

5 Performance
The firmware supports full duplex UART communication. It also supports UART packets with eight data bits,
least significant bit (LSB) first, no parity bit, and one stop bit. Because two serial interfaces are required, thisfirmware can only be used on MSP430 MCUs that have at least two USCI modules.
The firmware creates two 100-bytes buffer to hold the data in the conversion. After the data is stored in thebuffer, the next conversion is performed. Therefore, the maximum number of bytes sent in a single transmission
cannot exceed 100 bytes (including the frame header). If you require packets larger than 100 bytes of data insingle transmission, modify the two parameters I2C_TO_UART_BUFF_SIZE and UART_TO_I2C_BUFF_SIZE in
the firmware to meet the requirements.
Table 5-1. Maximum Rates
Interface

Maximum Rate

I2C

400-kHz bit clock

UART

921600-bps baud rate

To change the baud rate of the UART interface or the clock frequency of the I2C interface, change the
UCA0BRW or UCB0BRW register in the code. In this application, SMCLK operates at 16 MHz. To change
this, see the MSP430FR4xx and MSP430FR2xx Family User's Guide for the proper configuration and the
MSP430FR231x Mixed-Signal Microcontrollers datasheet for the maximum I2C clock value. After making thesechanges, close the serial terminal, rebuild the code, reprogram and reset the MCU, and then reopen the terminal
with the new baud rate.
The I2C clock speed and the UART baud rate can also be changed using UART commands (see Section 3 andSection 4). When the baud rate of the UART or the clock frequency of the I2C is changed by the UART, thechange takes effect immediately and is saved after power off and restart.

6

UART-to-I2C Bridge Using Low-Memory MSP430™ MCUsSLAA908A – SEPTEMBER 2019 – REVISED SEPTEMBER 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated

www.ti.com

Application Examples

To reduce power consumption while the MCU is not receiving or transmitting data, LPM0 is used. Other lowpower modes can achieve lower power consumption, but they might require an external crystal oscillator andcan limit the maximum baud rate due to increased wake-up times.

6 Application Examples
6.1 Test With I2C Slave Device
In this example, another MSP430FR2311 is used as the I2C slave device, and the I2C slave program is loadedinternally You can download the slave program for reference, and you need to add RX interrupts and buffers forcorrect operation. The slave address is 0x48. When receiving a write command sent by the host device, the datais stored in the buffer area. When receiving a read command sent by the host device, the slave device sends
incremental data starting at 0x00.
Figure 6-1 shows the serial port command sent by the I2C master to write data and read the data.
In the write example, the UART data command writes 8 bytes to the I2C slave. The command is composed ofthese bytes:
•
•
•
•
•

The first byte is 'S' (0x53) to indicate I2C start
The second byte indicates the slave address and write command (0x48 << 1 | 0 = 0x90)
The third byte indicates the length of the write data (0x08)
The next 8 bytes are the data to write to the slave (0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88)
The last byte is 'P' (0x50) to indicate I2C stop

In the read example, the UART data command reads 8 bytes from I2C slave.
••••

The first byte is 'S' (0x53) to indicate I2C start
The second byte indicates the slave address and the read command (0x48 <<1 | 1 = 0x91)
The third byte indicates the length of the read data (0x08)
The last byte is 'P' (0x50) to indicate I2C stop

Figure 6-1. I2C Write and Read
Figure 6-2 shows the waveform of the I2C write data. From the figure, we can see the start bit, slave address,
write command, write data and the end bit in SDA line.

Figure 6-2. I2C Write Data Waveform
Figure 6-3 shows the waveform of the I2C read data. From the figure, we can see the start bit, slave address,
read command, read data and the end bit in SDA line.

Figure 6-3. I2C Read Data Waveform

6.2 Read and Write EEPROM
This firmware was tested using EEPROM as the I2C slave device to verify the correctness of the firmware byreading and writing the EEPROM. The EEPROM address is 0x50. Figure 6-4 to Figure 6-7 show the read andwrite format.

SLAA908A – SEPTEMBER 2019 – REVISED SEPTEMBER 2021
UART-to-I2C Bridge Using Low-Memory MSP430™ MCUs
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated

7

Application Examples

www.ti.com

Figure 6-4. EEPROM Byte Write

Figure 6-5. EEPROM Page Write

Figure 6-6. EEPROM Random Read

Figure 6-7. EEPROM Sequential Read
The firmware first sets the I2C clock frequency to 100 kHz and sets the UART baud rate to 115200 by writing theinternal registers (Figure 6-8 shows the UART commands to read and write the internal register values). For thewrite test, the firmware writes 64 bytes of data to the EEPROM starting at address 0x0000. For the read test, thefirmware reads 64 bytes of data starting at address 0x0000.
Figure 6-8 shows the UART data commands to write to and read from the internal registers.
The write command is composed of these bytes:••••

The first byte is 'W' (0x57) to indicate a write to internal registers
The second byte is the internal register start address to write
The next four bytes are the data to write
The last byte is 'P' (0x53) to indicate stop

The read command is composed of these bytes:
8

UART-to-I2C Bridge Using Low-Memory MSP430™ MCUsSLAA908A – SEPTEMBER 2019 – REVISED SEPTEMBER 2021
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated

www.ti.com•••

Reference

The first byte is 'R' (0x52) to indicate a read from internal registers
The next four bytes are the addresses to read (0x00, 0x01, 0x02, 0x03)
The last byte is 'P' (0x53) to indicate stop

The final four bytes in the last row of Figure 6-8 are the values of the registers specified in the read command.

Figure 6-8. Write and Read Internal Register (Set I2C Clock Frequency and UART Baud Rate)
Figure 6-9 shows the UART commands to read and write the EEPROM.
The write command is composed of these bytes:
•
•
•
•
•
•

The first byte is 'S' (0x53) to indicate an I2C start
The second byte is the EEPROM I2C address and write command (0x50 << 1 | 0 = 0xA0)
The next three bytes is the length of the write data (0x42), which includes the 2-byte address plus the numberof bytes to write (64 in this case)
The next two bytes are the start address in the EEPROM to write
The next 64 bytes are the data
The last byte is 'P' (0x50) to indicate stop

The read command is composed of these bytes:
•
•
•
•
•
•
•
•

The first byte is 'S' (0x53) to indicate an I2C start
The second byte is the EEPROM I2C address and write command (0x50 << 1 | 0 = 0xA0 )The third byte is the length of the data (0x02), which is for the 2-byte address
The next two bytes are the start address in the EEPROM to read
The next byte is 'S' (0x53) to indicate an I2C restart
The next byte is the EEPROM I2C address and the read command (0x50<<1 | 1 = 0xA1)
The next byte is the length of the read data (64 bytes) (0x40)
The last byte is 'P' (0x50) to indicate stop

Figure 6-9 shows that the read data is the same as the write data.

Figure 6-9. Write and Read EEPROM Value

7 Reference
1.
2.
3.
4.
5.
6.

MSP430FR4xx and MSP430FR2xx Family User's Guide
MSP430FR231x Mixed-Signal Microcontrollers data sheet
UART-to-SPI Bridge Using Low-Memory MSP430TM MCUs
UART-to-UART Bridge Using Low-Memory MSP430TM MCUs
Microchip 128Kb I2C compatible 2-wire Serial EEPROM (24LC128)
NXP Master I2C bus Controller with UART Interface (SC18IM700IPW)

8 Revision History
NOTE: Page numbers for previous revisions may differ from page numbers in the current version.
Changes from Revision * (20190912) to Revision A (20210929)
Page• Updated the numbering format for tables, figures, and cross references throughout the document..................1• Corrected Figure 2-2 I2C and UART Code Flow ................................................................................................2

SLAA908A – SEPTEMBER 2019 – REVISED SEPTEMBER 2021
UART-to-I2C Bridge Using Low-Memory MSP430™ MCUs
Submit Document Feedback
Copyright © 2021 Texas Instruments Incorporated

9

IMPORTANT NOTICE AND DISCLAIMER
TI PROVIDES TECHNICAL AND RELIABILITY DATA (INCLUDING DATA SHEETS), DESIGN RESOURCES (INCLUDING REFERENCEDESIGNS), APPLICATION OR OTHER DESIGN ADVICE, WEB TOOLS, SAFETY INFORMATION, AND OTHER RESOURCES “AS IS”
AND WITH ALL FAULTS, AND DISCLAIMS ALL WARRANTIES, EXPRESS AND IMPLIED, INCLUDING WITHOUT LIMITATION ANYIMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT OF THIRDPARTY INTELLECTUAL PROPERTY RIGHTS.
These resources are intended for skilled developers designing with TI products. You are solely responsible for (1) selecting the appropriate
TI products for your application, (2) designing, validating and testing your application, and (3) ensuring your application meets applicablestandards, and any other safety, security, regulatory or other requirements.
These resources are subject to change without notice. TI grants you permission to use these resources only for development of an
application that uses the TI products described in the resource. Other reproduction and display of these resources is prohibited. No license
is granted to any other TI intellectual property right or to any third party intellectual property right. TI disclaims responsibility for, and you
will fully indemnify TI and its representatives against, any claims, damages, costs, losses, and liabilities arising out of your use of theseresources.
TI’s products are provided subject to TI’s Terms of Sale or other applicable terms available either on ti.com or provided in conjunction withsuch TI products. TI’s provision of these resources does not expand or otherwise alter TI’s applicable warranties or warranty disclaimers for
TI products.
TI objects to and rejects any additional or different terms you may have proposed. IMPORTANT NOTICE
Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265
Copyright © 2022, Texas Instruments Incorporated