|
|
View previous topic :: View next topic |
Author |
Message |
MeRKeZ
Joined: 04 Sep 2012 Posts: 11
|
18F4550 USB Problem |
Posted: Fri Dec 19, 2014 5:49 am |
|
|
Hi friends,
I'm developing a project which pc communicates pic via usb in, but there is a problem. I simulate it in Proteus and it works properly. When I first plug the cable to PC, there is a pop-up "your driver is installing" and after that it says "it's successful" but it doesn't work. When I plug it out and plug it in again, this time it says "Usb didn't recognize it" or it doesn't say anything it seems an exclamation in device manager.
What should I do?
Thanks in advance
Code: |
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)
//I'm using 20Mhz oscillator
#define USB_HID_DEVICE TRUE
#define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT
#define USB_EP1_RX_ENABLE USB_ENABLE_INTERRUPT
#define USB_EP1_TX_SIZE 64
#define USB_EP1_RX_SIZE 64
#include <pic18_usb.h>
#include <USB_Driver.h>
#include <usb.c>
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Fri Dec 19, 2014 6:09 am |
|
|
While I don't use that PIC anymore as I use external USB<>TTL modules now(cheaper,better) I suggest you use the 'search' feature of this forum to locate one of many 'hits' about this subject.
Aside from the D+, D- reversed it could be not having the 'sense' pin configured correctly or a code issue.
Be sure to do a 1Hz LED program before you try the USB stuff though as you MUST get the fuses coded right for the PIC to properly run USB !!
I do know the CCS supplied examples do work(the CDC ones).
You should report which compiler version you have, might be a bug,though I doubt it.
cheers
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Fri Dec 19, 2014 8:36 am |
|
|
What descriptor are you using?.
No sign of loading one....
Look at the CCS examples. EX_USB_HID.c shows how to load the drivers for an HID device. |
|
|
MeRKeZ
Joined: 04 Sep 2012 Posts: 11
|
|
Posted: Sat Dec 20, 2014 7:44 am |
|
|
Thanks for your answers.
I found the solution which was given by Ttelmah in a topic.
I changed this
Code: |
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGE
#use delay(clock=48000000)
|
into this
Code: |
#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#USE DELAY(CLOCK=20000000)
|
and it is done. Thanks Ttelmah.
Now, I have an another issue. I can't transmit the data properly.
This is C# code
Code: |
void sendData()
{
if ((control== 1) && (usbHidPort1.SpecifiedDevice != null))
{
control= 0;
int arrayLength= usbHidPort1.SpecifiedDevice.OutputReportLength;
byte[] sentData= new byte[arrayLength + 1];
sentData[0] = 0;
sentData[1] = data;
usbHidPort1.SpecifiedDevice.SendData(sentData);
}
}
private void usbHidPort1_OnDataRecieved(object sender, DataRecievedEventArgs args)
{
int arrayLength = usbHidPort1.SpecifiedDevice.OutputReportLength;
byte[] receivedData = new byte[arrayLength + 1];
receivedData = args.data;
control= receivedData [2]; //If transmission is successful, the data which is 1, comes
}
}
|
and this is CCS
Code: |
#include <18F4550.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#USE DELAY(CLOCK=20000000)
#define USB_HID_DEVICE TRUE
#define USB_EP1_TX_ENABLE USB_ENABLE_INTERRUPT
#define USB_EP1_RX_ENABLE USB_ENABLE_INTERRUPT
#define USB_EP1_TX_SIZE 64
#define USB_EP1_RX_SIZE 64
#include <pic18_usb.h>
#include <USB_Driver.h>
#include <usb.c>
void main()
{
set_tris_d(0x00);
output_d(0x00);
usb_init();
usb_task();
usb_wait_for_enumeration();
while(1)
{
while(usb_enumerated())
{
if (usb_kbhit(1))
{
usb_get_packet(1, receivedArray, 64); // get the data
receivedData= receivedArray[0];
output_d(receivedData);
sentData[0] = 1; // operation is succesfull and we send a data
usb_put_packet(Sabit, sentData,64, USB_DTS_TOGGLE);
}
}
}
|
As I observe, It only send the data in first time, not more but It works in proteus properly |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat Dec 20, 2014 8:20 am |
|
|
You went from this:
Quote: | #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGE
#use delay(clock=48000000) |
to this:
Quote: | #fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#USE DELAY(CLOCK=20000000)
|
What is your ACTUAL oscillator speed? 12MHZ (HSPLL) or 20MHZ (no PLL)?
The actual speed and your delay line MUST match.
Also, Ttelmah asked for your compiler version.... _________________ Google and Forum Search are some of your best tools!!!! |
|
|
MeRKeZ
Joined: 04 Sep 2012 Posts: 11
|
|
Posted: Sat Dec 20, 2014 9:10 am |
|
|
My oscillator is 20 Mhz. I think the compiler's version number is 4.068 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Sat Dec 20, 2014 10:58 am |
|
|
If your oscillator(primary, xtal and 2 caps) is 20MHz, then you'll need to change the fuses to get 4Mhz to the USB PLL. This is carefully written in the datasheet in the oscillator section. probably need to use the PLL prescaler to divide by 5 ( 20/5=4MHz).
I don't use the 4550 anymore, just going by memory...
hth
jay |
|
|
MeRKeZ
Joined: 04 Sep 2012 Posts: 11
|
|
Posted: Sat Dec 20, 2014 11:57 am |
|
|
According to this,
I changed my code but there is still same error. I'm just able to send first data and never more. I couldn't understand why
Code: |
#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV2,VREGEN
#USE DELAY(CLOCK=20000000)
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Dec 20, 2014 1:07 pm |
|
|
If you have a 20 MHz crystal, this is the setup you should use:
Quote: | #include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48M) |
|
|
|
ELCouz
Joined: 18 Jul 2007 Posts: 427 Location: Montreal,Quebec
|
|
Posted: Sat Dec 20, 2014 7:42 pm |
|
|
temtronic wrote: | While I don't use that PIC anymore as I use external USB<>TTL modules now(cheaper,better) I suggest you use the 'search' feature of this forum to locate one of many 'hits' about this subject.
Aside from the D+, D- reversed it could be not having the 'sense' pin configured correctly or a code issue.
Be sure to do a 1Hz LED program before you try the USB stuff though as you MUST get the fuses coded right for the PIC to properly run USB !!
I do know the CCS supplied examples do work(the CDC ones).
You should report which compiler version you have, might be a bug,though I doubt it.
cheers
Jay |
Me too... I ditched years ago using the pic as the usb device...
Much more reliable IMO to use the FTDI FT232R TTL to USB chip...
MUCH MUCH less trouble (drivers are rock solid!!!!) ... + don't need half ram and rom of the 2550 or 4550 just for usb functions...
Only problem right now with FTDI is regarding the FT232R clones (cheap one on eBay)
FTDI don't play well with those recently they cause to overwrite a portion of the eeprom of the clones thus having a PID of 0000 now unusable unless drivers are modified.
Downside of FTDI :
The genuine chips are damn expensive (7 to 10$ each) _________________ Regards,
Laurent
-----------
Here's my first visual theme for the CCS C Compiler. Enjoy! |
|
|
|
|
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
|