Part #/ Keyword
All Products

DIY: USB2S UART & IIC Adapter Setup Guide

2025-06-04 14:48:12Mr.Ming
twitter photos
twitter photos
twitter photos
DIY: USB2S UART & IIC Adapter Setup Guide

In the previous two DIY articles, DIY: USB2S Programmable USB-to-Serial Adapter Guide and DIY: How to Set USB-to-Serial Adapter Parameters, we explained the detailed interface and features of the Programmable USB-to-Serial Adapter Development Board, along with how to set and modify its parameters. In this DIY article, we’ll continue with the USB-to-UART and IIC applications of the Programmable USB-to-Serial Adapter Development Board. If you're interested, keep reading!

Programmable USB-to-UART/IIC/SMBus/SPI/CAN/1-Wire Adapter USB2S – USB-to-UART Application Steps

1. Driver Installation

USB2S is built with a USB-to-UART chip and supports CH340/CH341 drivers. Follow these steps to install the driver:
Double-click “CH341SER\SETUP.exe” (you can search for it online) to open the driver installation window.

Click the [Install] button. A message will appear shortly confirming "Driver installed successfully", as shown below:

image.png

Once the driver is installed successfully and USB2S is plugged into the computer's USB port, a new COM port will appear in Device Manager, as shown below:

image.png

 

2. USB-to-UART Working Principle

After the driver is installed, the PC communicates with the MCU through COMx. When USB2S is in UART transparent transmission mode (enabled by default), the MCU transparently forwards bidirectional data between UART1 and UART2. That is, data can be transferred in both directions between the computer's COMx port and the USB2S external UART2 port. Below is a simplified diagram of how it works:

image.png

The above method uses MCU firmware to enable transparent UART1↔UART2 data transfer.
Alternatively, for a true USB-to-UART setup, you can disable the MCU using jumper wires and connect an external UART device directly to the UART1 interface.

image.png

For most applications, the first method is sufficient.

 

Programmable USB-to-UART/IIC/SMBus/SPI/CAN/1-Wire Adapter USB2S – UART-to-IIC Application

1. AT24Cxx EEPROM Chip

1.1. Chip Overview

The AT24Cxx is a rewritable EEPROM memory chip. “xx” indicates the capacity in kilobits. The USB2S board comes with one AT24Cxx chip by default (AT24C02), with a device address of 0xA0.

According to the AT24Cxx datasheet, the read/write timing sequences are as follows:

Write Sequence:

· Send a START signal on the IIC bus

· Send the chip write address (0xA0)

· Send the EEPROM memory address to access

· Continuously send multiple bytes of data to be written

· Send a STOP signal to end communication

Read Sequence:

· Send a START signal on the IIC bus

· Send the chip write address (0xA0)

· Send the EEPROM memory address to access

· Send a START signal again

· Send the chip read address (0xA1)

· Continuously read output data from the IIC bus

· Send a STOP signal to end communication

1.2. Writing Data to AT24C02

To write four bytes (30 31 32 33) to address 0~3 of AT24C02, send the following string via UART1: [IIC][START][WT6H]A0 00 30 31 32 33[STOP]

Explanation:

· [IIC] — Target interface is IIC

· [START] — Issue a start signal from the target interface

· [WT6H] — Send 6 bytes in hexadecimal format

· A0 00 — Chip write address + EEPROM memory address

· 30 31 32 33 — 4 bytes of data to write to AT24C02

· [STOP] — Issue a stop signal to end this transmission

 

1.3 Reading Data from AT24C02

To read 4 bytes of data starting from address 0 of AT24C02:

Send the following string to UART1: [IIC][START][WT2H]A0 00[START][WT1H]A1[RD4N][STOP]

Expected return from UART1: 4 bytes (hex): 30 31 32 33

Explanation:

· [IIC] — Target interface is IIC

· [START] — Issue a start signal

· [WT2H] — Send 2 bytes in hexadecimal format

· A0 00 — Chip write address + memory address to access

· [START] — Send another start signal

· [WT1H] — Send 1 byte in hexadecimal format

· A1 — Chip read address

· [RD4N] — Read 4 bytes continuously

· [STOP] — Send a stop signal to end transmission

 

1.4 Cross-Page Data Writing

AT24C02 has pages of 8 bytes each. EEPROM addresses 0–7 belong to page 1, 8–15 to page 2, and so on. When writing across page boundaries, you must send a STOP signal after finishing each page so the chip can store the current page data. Afterward, start a new write sequence for the next data.

Note: The chip requires a short amount of time to store data. You should wait before starting a new communication or check for readiness—if you get [ERRxxx], the chip is busy, and you must resend until there is no error.

Example: To write 10 bytes starting from EEPROM address 0, first write addresses 0–7, delay, then write addresses 8–9.

[IIC][START][WT10H]A0 00 00 01 02 03 04 05 06 07[STOP][DELAY50][IIC][START][WT4H]A0 08 08 09[STOP]

Example: Write a string directly to the chip:

[IIC][START][WT2H]A0 00[WT8S]87654321[STOP][DELAY50][IIC][START][WT4H]A0 08 38 39[STOP]

Done!

* Solemnly declare: The copyright of this article belongs to the original author. The reprinted article is only for the purpose of disseminating more information. If the author's information is marked incorrectly, please contact us to modify or delete it as soon as possible. Thank you for your attention!