Você está na página 1de 28

Microchip Technology Inc.

WebSeminar

Emulating RS-232 over USB with PIC18F4550 December 10 th, 2004

2004 Microchip Technology Incorporated. All Rights Reserved. 1

Emulating RS -232 Over USB with PIC18F4550

Welcome to Microchip Webseminar My name is Rawin Rojvanit and I am an applications engineer here at Microchip Technology. With the introduction of the PIC18F4550 family, which has a full-speed USB peripheral, many more USB applications have become possible. One such application is the emulation of RS-232 over USB.

Microchip Technology Inc. WebSeminar

Agenda
l

Brief overview of RS-232 emulation over USB PICDEM FS USB Demo Board

Where to find more information

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

This presentation is only about 20 minutes long and not every thing can be explained here. The goal of this presentation is to describe what the RS-232 Emulation over USB is, what it is useful for, what Microchip is providing, and where to find more information.

Microchip Technology Inc. WebSeminar

USB Terminology
l

USB Universal Serial Bus

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

For those that are new to USB, I would like to introduce a few terminologies. USB stands for Universal Serial Bus. USB has literally become the standard peripheral interface for every personal computer.

Microchip Technology Inc. WebSeminar

USB Terminology
l l

USB Universal Serial Bus CDC Communication Device Class

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

CDC stands for Communication Device Class. This is a device level protocol specification defined by the USB association body. It defines the rules of how a USB host and a USB peripheral should communicate as a communication device. Specifically, the CDC specification defines a wrapper protocol layer around other communication protocols allowing them to be transported over the USB interface. A standardized specification also allows a USB host and a USB peripheral to be developed independently. As I will explained later on in this presentation, no work or modification is required on the PC side to implement the RS-232 emulation over USB. This is so because Windows 2000 and XP already come with a driver which provides the RS-232 emulation capability as defined in the Communication Device Class Specification. Therefore the only things left to do is for the embedded device to have the hardware and firmware supports that conform to the CDC specification.

Microchip Technology Inc. WebSeminar

USB Terminology
l l

USB Universal Serial Bus CDC Communication Device Class VID Vendor ID

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

VID stands for Vendor ID. Vendor ID is a 16-bit number assigned by the USB organization body. This number has to be purchased by each manufacturer in order to market and sell a product.

Microchip Technology Inc. WebSeminar

USB Terminology
l l

USB Universal Serial Bus CDC Communication Device Class VID Vendor ID PID Product ID

l l

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

PID stands for Product ID and it is also a 16-bit number. Therefore each manufacturer has 65,536 Product IDs to use.

Microchip Technology Inc. WebSeminar

USB Terminology
l l

USB Universal Serial Bus CDC Communication Device Class VID Vendor ID PID Product ID Every product is required to have a unique combination of VID and PID

l l l

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

Microchip Technology Inc. WebSeminar

USB Terminology
l l

USB Universal Serial Bus CDC Communication Device Class VID Vendor ID PID Product ID Every product is required to have a unique combination of VID and PID www.usb.org
Emulating RS -232 Over USB 8

l l l

2004 Microchip Technology Incorporated. All Rights Reserved.

More information can be found on www.usb.org

Microchip Technology Inc. WebSeminar

RS-232 Emulation over USB


HyperTerminal UART Driver UART Hardware

RS-232

UART Hardware UART APIs PIC18F4550 Firmware Application

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

The emulation of RS-232 over USB provides an easy migration path for an embedded application. The serial communication has traditionally been the most common method of transferring data between a PC and an embedded device. This slide shows that traditional method of transferring data over the RS-232 interface. The top half represents a personal computer and the bottom half represents an embedded application. The HyperTermina l is a Windows program that is used here as an example of an end application. Many computers no longer have a serial port. This fact causes a headache for many embedded system designers and a new solution is needed. An answer is to use USB.

Microchip Technology Inc. WebSeminar

RS-232 Emulation over USB


HyperTerminal HyperTerminal UART Driver UART Hardware UART Driver CDC Driver USB Hardware

RS-232

USB

UART Hardware UART APIs Firmware Application

USB Hardware USB UART APIs Firmware Application PIC18F4550

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

10

This slide shows the migration path from RS-232 to USB. The UART physical layer is replaced with the USB hardware layer. Since CDC is a standard USB class, Microsoft has implemented a driver which supports the RS-232 interface emulation. On the PC side, the CDC driver provides the linking layer between the USB hardware and the UART driver. This allows the end application to remain unchanged because from its perspective, it still sees the RS-232 interface. As for the embedded application side, the PIC18F4550 has a full-speed USB peripheral. In addition, Microchip also provides the CDC RS-232 Emulation Reference Project which provides necessary application programming interfaces.

10

Microchip Technology Inc. WebSeminar

PICDEM TM FS USB Demo Board


l

Assume that the CDC RS-232 Emulation Reference Project is programmed on the microcontroller
Switch 2 & 3
S2 S3 Serial Port

ICD2 Connector USB Port

RS232 RST

Reset Switch

18F4550

Power Connector

POT

Potentiometer

PICDEM FS USB Demo Board


2004 Microchip Technology Incorporated. All Rights Reserved. Emulating RS -232 Over USB 11

I would like to introduce you to the PICDEM FS USB Demo Board. This board can be purchased from buy.microchip.com or any Microchips distributors. It provides a hardware platform for demonstrating the USB capability of the PIC18F4550 family of devices. Assuming that the board has the CDC RS-232 Emulation Reference Project loaded, I will next show you how the demo board would be recognized by Windows Operating System.

11

Microchip Technology Inc. WebSeminar

Device Manager
l l

Two physical RS-232 ports PICDEM FS USB Board is not connected

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

12

12

Microchip Technology Inc. WebSeminar

Installing CDC driver in Windows XP


l l

Connect the demo board to a PC Windows should detect a new USB device

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

13

13

Microchip Technology Inc. WebSeminar

Specifying INF file location

C:\MCHPFSUSB\fw\CDC\inf\win2k_winxp
Emulating RS -232 Over USB 14

2004 Microchip Technology Incorporated. All Rights Reserved.

A standard INF file for the Communication Device Driver is not provided by Microsoft. One is provided by microchip. Example INF file is part of the CDC RS-232 Emulation Reference Project. Once installed, it can be found in directory listed on this slide. USB Product ID and Vendor ID are also contained in the INF file. This means when you use the reference project, you should change the IDs in both the firmware and INF files.

14

Microchip Technology Inc. WebSeminar

Installation Complete
l l

Two physical RS-232 ports PICDEM FS USB Board is connected

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

15

15

Microchip Technology Inc. WebSeminar

Using HyperTerminal
l l

Launch HyperTerminal Type in a name for a new connection, and hit OK

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

16

16

Microchip Technology Inc. WebSeminar

HyperTerminal: Connect To
l

Select the new COM port that was added during USB CDC installation and hit OK

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

17

17

Microchip Technology Inc. WebSeminar

HyperTerminal: COM Properties


l l

Hit OK Terminal is now ready

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

18

18

Microchip Technology Inc. WebSeminar

Default Firmware Demonstration


l

Now, hit switch S2 on the demo board, you should see the message below

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

19

19

Microchip Technology Inc. WebSeminar

HyperTerminal: Important Note


l

Before physically disconnecting a USB device, you must hang up the connection first, otherwise, the program must be closed and opened again the next time a USB device is connected.

Lets take a look at the APIs


Emulating RS -232 Over USB 20

2004 Microchip Technology Incorporated. All Rights Reserved.

Lets take a look at the APIs provided by the CDC reference project.

20

Microchip Technology Inc. WebSeminar

CDC APIs
void putrsUSBUSART(const rom char *data); void putsUSBUSART(char *data); void mUSBUSARTTxRom(rom byte *pData, byte len); void mUSBUSARTTxRam(byte *pData, byte len); byte getsUSBUSART(char *buffer, byte len); byte mCDCGetRxLength(void);
2004 Microchip Technology Incorporated. All Rights Reserved. Emulating RS -232 Over USB 21

Detailed information of each function can be found in Application Note AN956

21

Microchip Technology Inc. WebSeminar

Reference Project is a Tutorial


Reset main InitializeSystem

MainLoop main.c USBDriverService(); CDCTxService();

USBTasks()

ProcessIO()

user.c Exercise_01(); Exercise_02();

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

22

22

Microchip Technology Inc. WebSeminar

Performance Analysis
l

Speed l 640 Kbits/s = 80 Kbytes/s l Faster than RS-232 (UART) l This solution is not possible with a lowspeed USB device because it does not have a bulk endpoint. Program Memory Usage: ~ 3 KB

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

23

23

Microchip Technology Inc. WebSeminar

Information on the Web

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

24

24

Microchip Technology Inc. WebSeminar

AN956 - Migrating Applications to USB from RS-232


l

Communication Device Class (CDC) firmware

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

25

25

Microchip Technology Inc. WebSeminar

CDC_RS232_Emulation.EXE
l

C:\MCHPFSUSB\

Workspace file: MCHPUSB.mcw Output file: MCHPUSB.hex INF file for Windows Installation

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

26

26

Microchip Technology Inc. WebSeminar

RS-232 to USB Migration


l

Emulates RS-232 over USB = Easiest Transition No change for the PC application l Continues using COM1, COM2, etc. CDC RS-232 Emulation Reference Project is freely downloadable from www.microchip.com

2004 Microchip Technology Incorporated. All Rights Reserved.

Emulating RS -232 Over USB

27

27

Microchip Technology Inc. WebSeminar

Thank You

2004 Microchip Technology Incorporated. All Rights Reserved. 28

Emulating RS -232 Over USB with PIC18F4550

28

Você também pode gostar