emulatingrs-232overusb_121004

28
Microchip Technology Inc. WebSeminar 1 © 2004 Microchip Technology Incorporated. All Rights Reserved. Emulating RS -232 Over USB with PIC18F4550 1 Emulating RS-232 over USB with PIC18F4550 December 10 th , 2004 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.

Upload: mbvirtual

Post on 09-Oct-2014

109 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

1

© 2004 Microchip Technology Incorporated. All Rights Reserved. Emulating RS-232 Over USB with PIC18F4550 1

Emulating RS-232 over USB with PIC18F4550

December 10th, 2004

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.

Page 2: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

2

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

Agenda

l Brief overview of RS-232 emulation over USB

l PICDEM™ FS USB Demo Board

l Where to find more information

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.

Page 3: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

3

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

USB Terminology

l USB – Universal Serial Bus

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.

Page 4: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

4

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

USB Terminology

l USB – Universal Serial Busl CDC – Communication Device Class

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.

Page 5: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

5

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

USB Terminology

l USB – Universal Serial Busl CDC – Communication Device Class

l VID – Vendor ID

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 tomarket and sell a product.

Page 6: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

6

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

USB Terminology

l USB – Universal Serial Busl CDC – Communication Device Class

l VID – Vendor IDl PID – Product ID

PID stands for Product ID and it is also a 16-bit number.

Therefore each manufacturer has 65,536 Product IDs to use.

Page 7: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

7

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

USB Terminology

l USB – Universal Serial Busl CDC – Communication Device Class

l VID – Vendor IDl PID – Product IDl Every product is required to have a unique

combination of VID and PID

Page 8: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

8

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

USB Terminology

l USB – Universal Serial Busl CDC – Communication Device Class

l VID – Vendor IDl PID – Product IDl Every product is required to have a unique

combination of VID and PIDl www.usb.org

More information can be found on www.usb.org

Page 9: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

9

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

RS-232 Emulation over USB

HyperTerminal

UART Driver

UART Hardware

UART Hardware

UART APIs

Firmware Application

RS-232

PIC18F4550

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.

Page 10: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

10

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

RS-232 Emulation over USB

HyperTerminal

UART Driver

UART Hardware

UART Hardware

UART APIs

Firmware Application

RS-232

HyperTerminal

UART Driver

USB Hardware

USB Hardware

USB UART APIs

Firmware Application

USB

CDC Driver

PIC18F4550

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 applicationprogramming interfaces.

Page 11: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

11

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

PICDEM FS USB Demo Board

Potentiometer

Switch 2 & 3

Serial Port

18F4550

POT

S2 S3

RST

Power Connector

USB Port

ICD2Connector

RS232

Reset Switch

PICDEMTM FS USB Demo Board

l Assume that the CDC RS-232 Emulation Reference Project is programmed on the microcontroller

I would like to introduce you to the PICDEM FS USB Demo Board. This board can be purchased from buy.microchip.com or any Microchip’s 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 berecognized by Windows Operating System.

Page 12: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

12

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

Device Manager

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

Page 13: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

13

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

Installing CDC driver in Windows® XP

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

Page 14: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

14

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

Specifying INF file location

l C:\MCHPFSUSB\fw\CDC\inf\win2k_winxp

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.

Page 15: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

15

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

Installation Complete

l Two physical RS-232 portsl PICDEM FS USB Board is connected

Page 16: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

16

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

Using HyperTerminal

l Launch HyperTerminall Type in a name for a new connection, and

hit “OK”

Page 17: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

17

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

HyperTerminal: Connect To

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

Page 18: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

18

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

HyperTerminal: COM Properties

l Hit “OK”l Terminal is now ready

Page 19: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

19

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

Default Firmware Demonstration

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

Page 20: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

20

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

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.

l Let’s take a look at the APIs

Let’s take a look at the APIs provided by the CDC reference project.

Page 21: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

21

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

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);

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

Page 22: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

22

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

Reference Project is a Tutorial

Reset main InitializeSystem

MainLoop

user.cExercise_01();Exercise_02();

USBTasks()

ProcessIO()

main.cUSBDriverService();

CDCTxService();…

Page 23: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

23

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

Performance Analysis

l Speedl 640 Kbits/s = 80 Kbytes/sl Faster than RS-232 (UART)l This solution is not possible with a low-

speed USB device because it does not have a bulk endpoint.

l Program Memory Usage: ~ 3 KB

Page 24: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

24

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

Information on the Web

Page 25: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

25

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

AN956 - Migrating Applications to USB from RS-232

l Communication Device Class (CDC) firmware

Page 26: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

26

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

CDC_RS232_Emulation.EXE

Workspace file: MCHPUSB.mcw

Output file: MCHPUSB.hex

INF file for Windows Installation

l C:\MCHPFSUSB\

Page 27: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

27

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

RS-232 to USB Migration

l Emulates RS-232 over USB = Easiest Transition

l No change for the PC applicationl Continues using COM1, COM2, etc.

l CDC RS-232 Emulation Reference Project is freely downloadable from www.microchip.com

Page 28: EmulatingRS-232overUSB_121004

Microchip Technology Inc.WebSeminar

28

© 2004 Microchip Technology Incorporated. All Rights Reserved. Emulating RS-232 Over USB with PIC18F4550 28

Thank You