|
|
View previous topic :: View next topic |
Author |
Message |
cile
Joined: 10 May 2009 Posts: 17
|
USB communication 18F4550 |
Posted: Wed May 13, 2009 10:27 am |
|
|
Hello ,
I'm using for first time USB communication with PIC.
I just want to send the data from PC to 18F4550 and back.
What I have to do. Is it possible to explain me.
I read a lot about USB on the internet, and there is so many source codes, HID drives ... etc, really I'm confused.
Shoud I use for this communication "ex_ usb_hid.c"??
I know that this is a difficult question, but I hope on the help...
P.S. my english is not so good..
THANK YOU !!!!!!! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 13, 2009 1:15 pm |
|
|
To test the CCS HID demo, do this:
Download the CCS USB development kit files:
http://www.ccsinfo.com/compilerupdates.php
You need to have current "maintenance" in effect with CCS to be
able to download these files.
The USB files have a Windows application called Hiddemo.exe
This runs on your PC. It allows you to communicate with your
18F4550 board that is connected to your PC with a USB cable.
The HID example source file for the PIC USB code is here.
Quote: | c:\program files\picc\examples\ex_usb_hid.c |
This program must be compiled and programmed into your 18F4550
You can use the example source files in the USB kit, but they are old.
They are dated 7-1-2005. The current (vs. 4.092) USB example files
that come with the compiler are dated 3-27-2009.
The Ex_usb_hid.c file has many #define statements in it that must be
carefully considered.
1. It's setup to expect that the Microchip Explorer board is used.
If you don't have that board, then you need to change the #define to 0,
instead of the default value of 1. Example:
Code: | #define __USB_PIC_EXPLORER16__ 0 |
2. The Microchip Explorer board has LEDs on some of the PIC pins.
If your board has LEDs on different pins, then you need to change the
#define statements. For example, the Explorer board has LED1 on
pin A5. I'm using the PicDem2-Plus which has LEDs on pins B0-B3.
So I chose pin B2 for LED1:
Code: |
#if __USB_PIC_PERIF__
#DEFINE LED1 PIN_B2 // Changed for PicDem2-Plus (was A5)
|
3. If you are using the 18F4550, then the Ex_usb_hid.c file has an #elif
statement to select the correct fuses for that PIC. However, the #fuses
are setup to expect a 20 MHz crystal. It's easier if you use that crystal.
If you use another frequency, the #fuses will have to be changed.
4. The source file has a schematic of two 100K resistors for the USB
connection sense circuit. That circuit will have to be built on your board
by you. (Unless you have a board that already has it).
5. There are two more #define statements for LEDs on the Microchip
Explorer board that will have to be changed to fit your board.
These two #define statements are located farther down in the file than
the first LED1 statement. Example:
Code: |
#define LED2 PIN_B0 // Changed for PicDem2-Plus (was B4)
#define LED3 PIN_B1 // Changed for PicDem2-Plus (was B5)
|
6. On the Microchip Explorer board, the polarity of the LEDs is such that
they are turned on by setting the PIC pin to a low level. On my board,
the LEDs are turned on by setting them to a high level. CCS has macros
to allow you to set the polarity of the LEDs. I changed them as shown
below:
Code: | #define LED_ON(x) output_high(x) // Changed for PicDem2-Plus (was output_low)
#define LED_OFF(x) output_low(x) // Changed for PicDem2-Plus (was output_high) |
7. If you are making your own board, you will need to add a USB
connector to it. Make sure that the connections are done correctly.
Look at pinouts at a website like this, and also some other sites:
http://pinouts.ru/Slots/USB_pinout.shtml
Use a voltmeter to confirm which pin on the USB cable (from your PC)
has +5v on it. This will tell you which pin is pin 1. Be very careful
about this.
8. Make sure you have the required capacitor on the Vusb pin on the
PIC. I used a 4.7 uF Tantalum cap and it worked OK.
9. If your board has any existing circuits on the 18F4550's USB pins,
you will need to remove them. For example, on the PicDem2-Plus,
there is a 4.7K pull-up resistor on pin C4. I removed it.
There is a "trick" to make the Hiddemo.exe program work. You have
to configure it first:
In the Hiddemo.exe program, you need to go to the Files menu and
select the CCS HID board as the device. Then you can click on the
"Establish Connection" button and it will connect OK. Make sure your
18F4450 board is powered-up and connected to the PC with a USB
cable. Then the Hiddemo program should "see" the board and it will
appear in the Files menu of that program. |
|
|
Ttelmah Guest
|
|
Posted: Wed May 13, 2009 1:56 pm |
|
|
As a 'comment' though, whether HID is the best choice for you, depends on what you actually want to transfer (quantity of data), and what you want to talk _to_.
USB is a generic 'transfer medium', which supports transferring data in formats designed to handle a number of particular device 'types'. Some, have built in drivers in Windows, so an HID device (human interface device), is designed to handle data from things like keyboards, mice etc. For some applications, a 'CDC' device (which by default is seen like a serial port), may be the better choice, while if larger transfers are involved, a 'bulk' transfer device (designed for things like disk drives etc.), may be the best choice.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|