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

Getting Windows to recognize USB connection

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



Joined: 03 Jan 2011
Posts: 34

View user's profile Send private message

Getting Windows to recognize USB connection
PostPosted: Wed Jan 18, 2012 12:27 am     Reply with quote

Hi,

I've been trying for days now trying to get windows to recognize my usb connection but all i keep getting is a 'usb device not recognized message'.
I just need to be able to transfer data through this connection.

I'm using pic18f25j50, running a 20Mhz crystal, and using compiler 4.093.
Im trying to connect to Windows 7 32bit.

What do I have to do on the windows side? I downloaded the 'Microchip Application Libraries v2011-12-05 Windows' framework, but I'm not sure how do I use it. Which driver exactly do I have to use when I try installing the unrecognized usb device?

I tried the examples provided by ccs, but none of the examples seem to even get windows to realise theres a USB trying to connect to it. Then when i tried this following code, the 'usb device not recognized' message appears. But I cant install any drivers for it. I really need some help here. Thanks

Code:

#include "18F25j50.h"

#fuses HS, NOWDT, NOPROTECT,NODEBUG, PLL5,NOCPUDIV,RTCOSC_T1

#use delay(clock=20000000)
//#define USB_CON_SENSE_PIN PIN_B2
// Includes all USB code and interrupts, as well as the CDC API
#include <usb_cdc.h>
void main(void)
{
   BYTE i;
   UPUEN=1;

   
   usb_init_cs();

   while(TRUE)
   {
      usb_task();
      if (usb_enumerated())
      {
         if (usb_cdc_kbhit())
         {
            i = toupper(usb_cdc_getc());
           
            if (i == 'R')
            {
               printf(usb_cdc_putc, "Sending a R Back");
            }
           
            if (i == 'W')
            {
               printf(usb_cdc_putc, "Sending a W Back");
            }
         }
      }
   } 
}
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Jan 18, 2012 12:34 am     Reply with quote

Usually, problems of this kind are caused by device hardware problems, e.g. wiring errors and not related to Windows.
asdf85



Joined: 03 Jan 2011
Posts: 34

View user's profile Send private message

PostPosted: Wed Jan 18, 2012 1:17 am     Reply with quote

Normally when I try installing the cdc9Xpt1.inf file as its driver, it does show 'usb to rs232'. But when i click next to install, it says 'windows encountered a problem installing the driver for your device'. 'The system cannot find the file specified'.

What file is it referring to?
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Wed Jan 18, 2012 3:09 am     Reply with quote

Minor comment (should still work, but 'pushing things'). Usb_init_cs, is the version for where you _are_ using a connection sense pin. You have this disabled, so should be using usb_init instead.
Then you are using the wrong driver file. cdc9xpt1, is for win '9x'. 95, 98 etc.. The one for Windows NT/XP/7, is cdcntxpvista.inf. It is in the nt,2000,XP,VISTA,7 subdirectory off the 'drivers' subdirectory of the compiler.
This is probably the main problem.

Best Wishes
asdf85



Joined: 03 Jan 2011
Posts: 34

View user's profile Send private message

PostPosted: Wed Jan 18, 2012 6:51 pm     Reply with quote

I've tried using just usb_init(). And also the cdcntxpvista.inf driver. It still doesnt work. Windows says it 'found driver software for your software but encountered an error while attempting to install it. The system cannot find the file specified'. However it does show the driver as 'usb to rs232'.

What about the Microchip Framework thing? What am i supposed to do with that?
asdf85



Joined: 03 Jan 2011
Posts: 34

View user's profile Send private message

PostPosted: Wed Jan 18, 2012 11:19 pm     Reply with quote

Also, should the 'usb_task()' function automatically get the usb connection enumerated? Or is there something else I need to add after that?

And, does the D+ and D- lines have to be pulled up or down? Currently I'm connecting it directly to the USB port.

Anothing question ive been wondering, whenever i try running the "ex_usb_serial.c", the program always gets stuck at the printf commands. I notice this coz when i run the debugger and stop it, its never moves past that first printf command, and the arrow points to the '#use rs232(UART1, baud=9600, errors)' line. whats causing it to stop there?
asdf85



Joined: 03 Jan 2011
Posts: 34

View user's profile Send private message

PostPosted: Thu Jan 19, 2012 2:17 am     Reply with quote

Thats strange...I just realised a simple program to send a byte over rs232 also doesn't work with this chip. And I've used rs232 many times with other chips. It just hangs when it reaches the putc or printf commands.
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Thu Jan 19, 2012 2:27 am     Reply with quote

Two fuses:

VREGEN - absolutely essential turns on the voltage regulator for USB.
USBDIV - also essential - says to clock the USB from the PLL. Otherwise it'll try to clock it directly from the crystal.

With these added I suspect you will find it'll now run.

The default USB code, uses the internal pullup's in the PIC for the USB lines. You don't want anything else on the D+/D- lines.

Best Wishes
asdf85



Joined: 03 Jan 2011
Posts: 34

View user's profile Send private message

PostPosted: Thu Jan 19, 2012 2:35 am     Reply with quote

These 2 fuses you mentioned, aren't among the list of fuses for the 18f25j50. How do I go about to turning it on in that case?
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Thu Jan 19, 2012 3:50 am     Reply with quote

Apologies, thought you were running the standard 4550/2550.
Reason though is that the clock fuses you have are wrong for your chip....

With the 26J50:
1) You have got 3.3v connected to the Vusb pin?. On the other chips there is an internal regulator for this (which is what Vregen enables). On your chip, _you_ must provide this (hence no Vregen fuse).
2) You can't run the CPU at 20MHz using USB with this chip.

To run full speed USB on this chip, the 'master clock' line inside the chip, _must_ be running at 48MHz (node 2 in the oscillator data). To do this, requires that the incoming clock is fed to the PLL, and divided to give 4MHz, then multiplied to give 48Mhz. This then generates this master line. Unlike the 4550/2550, where you can still take the incoming clock and feed it to the CPU, on your chip you can't.

So you need the fuses to say:

HSPLL - You _must_ use the PLL. Unlike the older chips where the USB uses the PLL whatever the CPU is doing, on this one, you have to enable it, and once enabled, it is used for both the CPU and the USB..
CPUDIV2 - this will bring the CPU clock back to 24MHz - closest you can get to the 20MHz rate you wanted to run.
Change your clock statement to 24MHz.

Currently your CPU will be running at 20MHz, but you'll be trying to run the USB at 20MHz, which won't work.....

Best Wishes
asdf85



Joined: 03 Jan 2011
Posts: 34

View user's profile Send private message

PostPosted: Fri Jan 20, 2012 3:15 am     Reply with quote

Hmm. In that case do I use a 4MHz crystal? And if I do, should my clock statement be 16MHz since Im running PLL? Actually I dont know much about PLL, just that i think it multiplies the crystal frequency by 4, right?

And thank you very much Ttelmah
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Fri Jan 20, 2012 8:48 am     Reply with quote

The PLL on the USB chips, is very different from the one on the other chips. The 'standard' PLL, just multiplies the incoming clock by 4. On the USB chips, the PLL, multiplies it's incoming frequency by _24_.

It _must_ have a 4MHz source.

In front of the USB PLL, there is a programmable divider, to divide the incoming clock to get 4MHz. The PLL5 fuse says to divide the incoming clock by 5, before feeding the USB PLL, so your 20MHz crystal will work fine.

The output of the PLL, is then divided by 2 before being fed to the rest of the circuitry (to ensure that the signal at this point has exactly a 50:50 mark/space ratio). This 48MHz signal feeds the USB.

On the 2550/4550 and their derivative chips, you have a choice at this point of feeding the CPU from the PLL source, or from the incoming clock, and applying a number of dividers before feeding the actual CPU.
However on your chip this option is not available. So the CPU clock has to be derived from the 48MHz generated by the PLL. The CPU can run at 48MHz, 24MHz, 16MHz, or 8Mhz from this, _or_ can be fed from the internal RC source.

So your 20MHz crystal is fine, but you can't run the CPU itself at 20Mhz and use the USB.

Best Wishes
asdf85



Joined: 03 Jan 2011
Posts: 34

View user's profile Send private message

PostPosted: Fri Feb 03, 2012 2:53 am     Reply with quote

Thanks Ttelmah. I was on a long break. Anway this helps my understanding better.

So if I use a 20MHz crystal, I must set PLL5. Then at the #USE DELAY, do I write it as #USE DELAY(clock=48MHz) even though the crystal is actually 20Mhz?
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Fri Feb 03, 2012 5:44 am     Reply with quote

If you are using CPUDIV1, then 'yes'.
The number used in the #use delay statement, must _always_ be the actual clock fed into the CPU. When using any of the PLL's, this differs from the actual 'crystal' frequency.

Best Wsihes
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