AN197 Silicon_Laboratories, AN197 Datasheet

no-image

AN197

Manufacturer Part Number
AN197
Description
Serial Communications Guide FOR THE Cp210x
Manufacturer
Silicon_Laboratories
Datasheet
S
Relevant Devices
This application note applies to the following devices:
CP2101, CP2102, CP2103
1. Introduction
This document is intended for developers creating products based on the CP210x USB to UART Bridge Controller.
It provides information about serial communications and how to obtain the port number for a specific CP210x
device. Code samples are provided for opening, closing, configuring, reading, and writing to a COM port. Also
included are GetPortNumWinXXXX() functions that can be copied and used to determine the port number on a
CP210x device by using its Vendor ID (VID), Product ID (PID), and serial number.
2. Opening a COM Port
Before configuring and using a COM port to send and receive data, it must first be opened. When a COM port is
opened, a handle is returned by the CreateFile() function that is used from then on for all communication. Here is
example code that opens COM3:
HANDLE hMasterCOM = CreateFile("\\\\.\\COM3",
The first parameter in the CreateFile() function is a string that contains the COM port number to use. This string will
always be of the form "\\\\.\\COMX" where X is the COM port number to use. The second parameter contains flags
describing access, which will be GENERIC_READ and GENERIC_WRITE for the example in this document, and
allows both read and write access. Parameters three and four must always be 0, and the flag in parameter five
must always be OPEN_EXISTING when using CreateFile() for COM applications. The sixth parameter should
always contain the FILE_ATTRIBUTE_NORMAL flag. In addition, the FILE_FLAG_OVERLAPPED is an optional
flag that is used when working with asynchronous transfers (this option is used for the example in this document).
If overlapped mode is used, functions that read and write to the COM port must specify an OVERLAPPED
structure identifying the file pointer, which is demonstrated in section 3.1. and section 3.2. (more information on
overlapped I/O is located at
serial_topic4). The seventh, and last, parameter must always be 0.
If this function returns successfully, then a handle to the COM port will be assigned to the HANDLE variable. If the
function fails, then INVALID_HANDLE_VALUE will be returned. Upon return check the handle and if it's valid, then
prepare the COM port for data transmission.
Rev. 0.6 10/07
E R I A L
C
GENERIC_READ | GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
0);
O M M U N I C A T I O N S
http://msdn.microsoft.com/library/en-us/dnfiles/html/msdn_serial.asp?frame=true -
Copyright © 2007 by Silicon Laboratories
G
U I D E F O R T H E
C P 2 1 0
AN197
X
AN197

Related parts for AN197

Related keywords