Rev. 0.5 3/13 Copyright © 2013 by Silico n Laboratories AN223
AN223
RUNTIME GPIO CONTROL FOR CP210X
1. Introduction
Some CP210x devices include GPIO pins that can be controlled by the PC using a Dynamic Link Library (DLL).
The default configuration of these pins is controlled by the software included in AN721, “CP210x/CP211x Device
Customization Guide,” available on the interface application note web page (http://www.silabs.com/products/
Interface/Pages/interface-application-notes.aspx). This document discusses reading and writing the state of these
pins with software.
The CP210x Port Read/Write Example illustrates how the GPIO latch can be read from and written to using the
CP210xRuntime.DLL. The functions in this API (CP210xRT_ReadLatch() and CP210xRT_WriteLatch()) give host-
based software access to the CP210x device’s GPIO latch using the USB connection as shown in Figure 1.
Figure 1. Main Window
The main window of the CP210x Port Read/Write Example contains one section to write the GPIO latch and
another to read the GPIO latch. Below that is a list to select a COM port and display boxes for the device part
number, product string, and serial number.
To write new values to the latch, select which GPIO pins to update, and set the pin state for each. Any GPIO pins
not selected to change will remain static when the “Write Latch” button is pressed. The “Write Latch” button calls
the CP210xRT_WriteLatch() function followed by the CP210xRT_ReadLatch() function, which updates the values
displayed in th e Read Latch portio n of the dialog. At any time, the “Read Latc h” button can be pr essed to read in
the current GPIO pin state of the device.
AN223
2 Rev. 0.5
2. Creating Custom Applications using CP210xRuntime.DLL
Custom applications can use the CP210x Runtime API implemented in CP210xRuntime.DLL. To use functions
implemented in CP210xRuntime.DLL, link CP210xRuntime.LIB with your Visual C++ 6.0 application. Include
CP210xRuntimeDLL.h in any file that calls functions implemented in CP210xRuntime.DLL.
3. CP210x Runtime API Functions
The CP210x Runtime API provides access to the GPIO port latch, and is meant for distribution with the product
containing a CP210x device.
CP210xRT_ReadLatch()—Returns the GPIO port latch of a CP210x device.
CP210xRT_WriteLatch()—Sets the GPIO port latch of a CP210x device.
CP210xRT_GetPartNumber()—Returns the 1-byte Part Number of a CP210x device.
CP210xRT_GetProductString ()—Returns the product str ing programmed to the device.
CP210xRT_GetDeviceSerialNumber ()—Returns the serial number programmed to the device.
CP210xRT_GetDeviceInterfaceString ()—Returns the interface string programmed to the device.
Typically, the user initiates communication with the target CP210x device by opening a handle to a COM p ort using
CreateFile() (See AN197: “Serial Communication Guide for CP210x”). The handle returned allows the user to call
the API functions listed above. Each of these functions is described in the following sections. Ty pe definitions and
constants are defined in the file CP210xRuntimeDLL.h.
Note: Functions calls into this API are blocked until completed. This can take several milliseconds depending on USB traffic.
3.1. CP210xRT_ReadLatch
Description: Gets the current port latch value from the device.
Supported Devices: CP2103, CP2104, CP2105, CP2108
Location: CP210x Runtime DLL
Prototype: CP210x_STATUS CP210xRT_ReadLatch(HANDLE Handle, LPWORD Latch)
Parameters: 1. Handle—Handle to the Com port returned by CreateFile().
2. Latch—Pointer for 4-byte return GPIO latch value [Logic High = 1, Logic Low = 0].
Return Value: CP210x_STATUS = CP210x_SUCCESS,
CP210x_INVALID_HANDLE,
CP210x_DEVICE_IO_FAILED
CP210x_FUNCTION_NOT_SUPPORTED