Help with USB communication using PIC18F4550

Status
Not open for further replies.

mariuszoll

Member level 5
Joined
Aug 28, 2012
Messages
82
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,286
Activity points
2,147
Hi,

I have to implement a communication between PC and a board with PIC18F4550. The problem is the fact that, this is the 1st time when I do it.
Could you help me please with an example of C code in order to understand how to do it.

Thank you in advance.
 


Microchip provides many code examples for their processors. I have included the link that will help you search for source code examples for the PIC18...

**broken link removed**

Furthermore, Microchip provides a royalty-free USB stack for their processors, including the PIC18.

**broken link removed**

These two things should provide you with a very good start. Once you have looked these over, start writing code; as you run into problems we will be more than happy to assist you.

Regards,
Willis
 

if you download Microchip's application framework library
**broken link removed**

and look in the Microchip Solutions v2012-07-18\USB directory there are number of USB device examples
if you don't need high speed data transfers (max 64Kbit/sec) the Device - HID - Custom Demos is simple to adapt, uses the standard Windows HID drivers and comes with example code for Microsoft Visual Studio C++
 

mariuszoll, easiest software way to comunicate between PC and microcontroller is using RS232 protocol (this is only my personal oppion, not oppion of electronic community). But, how you probablly know, serial (RS232) port is legacy now. So, USB is normal choice for communication link.

USB code could be complicate, specially for you, if you are a begginer in this. So, try to read something about convertiing USB to RS232, with virtual COM port on PC side. For that, purpose, I propose you to use FTDI232 chip on microcontroller side. I have a very good experience with that chip. It is easy to use them, there are all drivers you need, and you can use UART syntax on microcontroller side. For documentation of FTDI chip, internet will be enough.

If you use FTDI chip, you can use every microcontroller you have, not only microcontroller which support USB, like your PIC18F4550 does.
 

In my opinion the simplest and most straight forward method is the implementation of a Communication Device Class (CDC).

CDC has several distinct advantages:

1. Requires no additional or custom drivers.

2. Uses the existing Microsoft Windows driver, usbser.sys.

3. Only requires the modification of the driver, INF file to ensure proper driver installation.

4. A CDC implements a virtual serial port, compatible with many existing applications.

5. The PIC18 CDC API is simple and intuitive, requiring only a few API calls.

The following document discusses the implementation of a CDC device:

Migrating Applications to USB from RS-232 UART with Minimal Impact on PC Software


BigDog
 

BigDog,

You are right, your proposal is better than mine. I change my oppion about USB communication between PC and microcontroller
 

Hi,

I would like to thank you for your quick replies, but I still have one more question:
I use the internal oscillator of the uC in my project, at a 4Mhz frequency.
Is it possible to use the same frequency in order to implement the USB communication?

Thank you
 

Hi,

Could you tell me please from where can I get the VID and PID?

Thank you
 

You have to create VID and PID. If you are using mikroC then go to Tools > HID Terminal. then click descriptor tab. Give a value to VID and PID or u you can use the default 1234 and 0001 values. Then give any name for Vendor name and Product name. Select the language like mikroC and then click save descriptor. save the file to your project folder. You have to add the file to the project.
 

Could you tell me please from where can I get the VID and PID?

VIDs are tightly controlled and licensed by USB-IF, Inc., there are numerous companies which provided sublicensing of VIDs for a fee.

You should NOT randomly choose a VID for a product, unless of course you wish to face serious litigation.


Fortunately, Microchip provides a VID/PID pair for testing, they also offer a VID/PID pair sublicensing service free of charge for product development and initial production limited to 10,000 units.

**broken link removed**

BigDog
 

internetuser2k12

about the second link it's awesome but the code he's using , I think it has a problem ... MikroC couldn't compile successfully , maybe because of using goto ??
also I put Lcd instead of Lcd8 , because the correct function called - Lcd_init();

can you help me ??

for all of you guys

can anyone make the code in this LINK work ?? cuz it gives me error messeges when I compile it
 
Last edited:

Hi,

Thank you very much bigdogguru for your piece of advice. It was very helpful for me, in order to display on PC Hyperterminal "Hello World" message from PIC18F4550. This was my first USB application.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…