CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

18F4550 USB Problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MeRKeZ



Joined: 04 Sep 2012
Posts: 11

View user's profile Send private message

18F4550 USB Problem
PostPosted: Fri Dec 19, 2014 5:49 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Dec 19, 2014 6:09 am     Reply with quote

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: 19544

View user's profile Send private message

PostPosted: Fri Dec 19, 2014 8:36 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Dec 20, 2014 7:44 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Dec 20, 2014 8:20 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Dec 20, 2014 9:10 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Dec 20, 2014 10:58 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Dec 20, 2014 11:57 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Dec 20, 2014 1:07 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Dec 20, 2014 7:42 pm     Reply with quote

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!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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