How To emulate a COMx port via USB using Microchip CDC
Firmware
Start communicating with a PC.
Follow the Tutorial in a few steps:
Notice that most of
these Steps are needed only for the 1st use !Step 1: Requirements:
- have a USB devlopment board
based on a PIC18F4550...
- have the device programmed with the USB boot
firmware code,
- have already sucessfully used the USB
BootloaderThat means you must follow the
UsbBootload
Tutorial
before doing this one !
If you don't want to
use the USB Bootloader, you must make some modifications in the CDC project
(change the Linker Script file to a normal one, set all Conf Bits, export a
complete hex file including Conf Bits...).Step 2: Install needed softwares and get CDC Firmware
Source CodeMicrochip MPLAB 7.00+ available from
http://www.microchip.com/ide/∞Microchip C18 2.40+ available from
http://www.microchip.com/c18/∞ (
check
all Config Options boxes when asked !)
Microchip
CDC Firmware Source Code∞ ("
CDC_RS232_Emulation.EXE∞")
Step 3:
Adapt the firmware to your board With a PICDEM FS-USB board (or
complete clone), nothing to change, go to next step.With a simplified
clone (without SELF_POWER_SENSE_IO nor USB_BUS_SENSE_IO), edit the
firmware:
Open MPLAB project :C:\MCHPFSUSB\fw\Cdc\MCHPUSB.mcp .
In usbcfg,
comment both lines (start with //):
#define
USE_SELF_POWER_SENSE_IO
#define USE_USB_BUS_SENSE_IO
Rebuild the project.
This will update .\_output\MCHPUSB.hex.
If you use another Full Speed USB
PIC (like 2455), also think to select your Device & replace the Linker
Scripts file.Step 4: Bootload
the CDC firmware in the PICConnect the USB cable. It powers the PIC
(not visible at this time).
Enter Boot Mode by pressing [S1 Reset] while
maintaining [S2 enter Boot].
Bootload the HEX firmware file located at:
C:\MCHPFSUSB\fw\Cdc\_output\MCHPUSB.hex
Step 5: 1st CDC detectionRestart the board
in user mode (reset while not pressing [S2 enter Boot]).
Normally, Windows
will start detecting a new USB unknow device.
Step 6: Manualy specify "Microchip CDC" INF driver to
MSWindowsAt this point, you must have a window asking a driver for
the new USB device.
The procedure depends on your Operating System
version.
Don't let Windows find automatically a driver, or you will have to
suppress the bad driver fille manualy!
Specify the driver location :
C:\MCHPFSUSB\fw\Cdc\inf\win2k_winxp (mchpcdc.inf)
Now it should be recognised
as "Communications Port" (COMx, COM3 for ex.).
You can verify in Windows
Device Manager.
Step 7:
Hyperterminal communicationRun MSWindows Hyperterminal (or others
like
this
one∞).
Start
Menu:Programms/Accessories/Communications/HyperTerminal Create a new
connection on COM3 with 115200 bauds rate (this value comes from cdc.c).
In
the Hyperterminal, click Connect (Call) !
Then (& only then), push S2.
It must print :
Microchip Technology Inc., 2004
PIC18F4550 Full-Speed
USB - CDC RS-232 Emulation Demo
Close the connection in the Hyperterminal
before unpluging USB (thus you can reconnect USB and reuse the
same connection in Hyperterminal without having to close/restart
it).
Next: Your own
programTo go further, try to do the examples proposed in user.c
.
See Microchip documentation :
AN956 Migrating Applications to USB from RS-232 UART∞Then, you can start writing your own PC Comm
application.