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 support@ccsinfo.com

Problem with USB
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
johnlook1975
Guest







Problem with USB
PostPosted: Wed Sep 26, 2007 8:02 pm     Reply with quote

Hi, I'm having some problens using USB. My device is PIC18F4550 I'm using a cap of 470nF and a 20MHz oscillator. I'm using the example ex_usb_serial.c but when I connect my device in the computer windows shows a message that the device wasn't recognize and the device plugged in USB port have bad function. I verified the connection and everything seens to be right someone could help me ?
Markdem



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

PostPosted: Wed Sep 26, 2007 10:30 pm     Reply with quote

Hi johnlook1975, Make sure that you have a bypass cap close to the PIC, about 100nf should do nice. You can also try to use a bigger cap on the VUSB pin.

Mark
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Thu Sep 27, 2007 3:59 am     Reply with quote

i had the same problem as you see topic here --> Tricky USB code (CCS RS232 DEMO)

solved adding a cap to the rail ,, no more than 10uf because if its usb powered it could suck to much power+ 0.1 uf ceramic close to the pic Vss & Vdd.
johnlook1975
Guest







Problem with USB
PostPosted: Thu Sep 27, 2007 12:45 pm     Reply with quote

Hi again, I put a cap between Vdd and Vss of 0,1uF, now when I connect the device to usb port it conects but 3 seconds later it disconnect automatically. Some could help me.
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Fri Sep 28, 2007 4:15 am     Reply with quote

do you have also a decoupling cap on the pic (ex:10uf electrolytic cap) ?

EDIT: is your project powered entirely by usb power ?

if yes check the current that your project is taking...

no more than 100 mA before authentification ... and after 500mA max !!

if you not follow/exceed the usb specs you might have random device disconnection on too much current drawn (its a protection).
johnlook1975
Guest







Problem with USB
PostPosted: Fri Sep 28, 2007 7:29 am     Reply with quote

Hi again, I made some changes that you said. I put a 10uF eletrolytic cap on pic and I powered my circuit with an external source, but it still have the same problem, the device connects and 3 seconds later it disconnects.
Ttelmah
Guest







PostPosted: Fri Sep 28, 2007 7:55 am     Reply with quote

Two questions.
Is your PC, using a Via chipset?.
I have seen very similar behaviour, on machines with some Via chipsets, when the 'default' WinXP driver is used, rather than the one from Via. Though the USB apparently works fine with most devices, it'll disconnect, sometimes after a certain number of characters, or the passage of an indeterminate time. Installing Via's own driver, fixed the problem.
Second. You haven't enabled the watchdog perchance?. Though the time involved doesn't 'ring any bells', as a default watchdog period, it could give this behaviour.
One comment. You speak about a 10uF capacitor. Have you got some small non electrolytic (polyester or ceramic) capacitors on the line as well. Preferably with one really close to the CPU. Though you'd normally think 'larger is better', in the case of capacitors, for some things, this is not the case, with aluminium electrolyte capacitors, behaving less well at filtering high frequencies, than their 'smaller' brethren. This is why if you look round a modern digital board, as well as the large capacitors in the supply, expect to see a small capacitor every few IC's round the board.

Best Wishes
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Fri Sep 28, 2007 8:01 am     Reply with quote

Also watch for the Standard OpenHCD Root USB Controller (look for universal serial bus controller in device manager)

there are some issue with this particular usb controller.
johnlook1975
Guest







Problem with USB
PostPosted: Fri Sep 28, 2007 9:55 am     Reply with quote

Hi, before anything, thanks for the help you gave to me.
I verify the chipset and it is not Via chipset. And I try to connect in other PC and it had the same problem.
I'm not using watchdog time, it is disabled. And I connect a 0,47uF ceramic cap between Vss and Vdd, but nothing changed.
Here is the code I'm using:
Code:


//set to 1 to use a PIC's internal USB Peripheral
//set to 0 to use a National USBN960x peripheral
#define __USB_PIC_PERIF__ 1

#if !defined(__PCH__)
 #error USB CDC Library requires PIC18
#endif


#if __USB_PIC_PERIF__
 #DEFINE LED1  PIN_A5
 #include <18F4550.h>
 #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,PLL5,CPUDIV1,VREGEN,USBDIV
 #use delay(clock=48000000)
#else //use the National USBN960x peripheral USBDIV
 #DEFINE LED1  PIN_B3
 #include <18F452.h>
 #fuses HS,NOWDT,NOPROTECT,NOLVP
 #use delay(clock=20000000)
#endif   //endif check to see which peripheral to use

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

/////////////////////////////////////////////////////////////////////////////
//
// If you are using a USB connection sense pin, define it here.  If you are
// not using connection sense, comment out this line.  Without connection
// sense you will not know if the device gets disconnected.
//       (connection sense should look like this:
//                             100k
//            VBUS-----+----/\/\/\/\/\----- (I/O PIN ON PIC)
//                     |
//                     +----/\/\/\/\/\-----GND
//                             100k
//        (where VBUS is pin1 of the USB connector)
//
/////////////////////////////////////////////////////////////////////////////
///only the 18F4550 development kit has this pin
#if __USB_PIC_PERIF__ && defined(__PCH__)
 #define USB_CON_SENSE_PIN PIN_B2
#endif


#include <usb_cdc.h>

/////////////////////////////////////////////////////////////////////////////
//
// Configure the demonstration I/O
//
/////////////////////////////////////////////////////////////////////////////
#define LED2 PIN_B4
#define LED3 PIN_B5
#DEFINE BUTTON PIN_A4
#define LED_ON output_low
#define LED_OFF output_high


/////////////////////////////////////////////////////////////////////////////
//
// usb_debug_task()
//
// When called periodically, displays debugging information over serial
// to display enumeration and connection states.  Also lights LED1 based upon
// enumeration and status.
//
/////////////////////////////////////////////////////////////////////////////
void usb_debug_task(void) {
   static int8 last_connected;
   static int8 last_enumerated;
   int8 new_connected;
   int8 new_enumerated;
   static int8 last_cdc;
   int8 new_cdc;

   new_connected=usb_attached();
   new_enumerated=usb_enumerated();
   new_cdc=usb_cdc_connected();

   if (new_enumerated)
      LED_ON(LED1);
   else
      LED_OFF(LED1);

   if (new_cdc)
      LED_ON(LED2);
   else
      LED_OFF(LED2);

   if (usb_cdc_carrier.dte_present)
      LED_ON(LED3);
   else
      LED_OFF(LED3);

   if (new_connected && !last_connected)
      printf("USB connected, waiting for enumaration...\r\n\n");
   if (!new_connected && last_connected)
      printf("USB disconnected, waiting for connection...\r\n\n");
   if (new_enumerated && !last_enumerated)
      printf("USB enumerated by PC/HOST\r\n\n");
   if (!new_enumerated && last_enumerated)
      printf("USB unenumerated by PC/HOST, waiting for enumeration...\r\n\n");
   if (new_cdc && !last_cdc) {
      printf("Serial program initiated on USB<->UART COM Port\r\n\n");
      printf(usb_cdc_putc, "\r\n\nCCS CDC (Virtual RS232) Example\r\n\n");
   }

   last_connected=new_connected;
   last_enumerated=new_enumerated;
   last_cdc=new_cdc;
}

void main(void) {
   char c;

   LED_OFF(LED1);
   LED_OFF(LED2);
   LED_OFF(LED3);

   printf("\r\n\nCCS CDC (Virtual RS232) Example\r\n");

  #ifdef __PCH__
   printf("PCH: v");
   printf(__PCH__);
  #else
   printf("PCM: v");
   printf(__PCM__);
  #endif
   printf("\r\n");

   usb_init_cs();

  #if !(__USB_PIC_PERIF__)
   printf("USBN: 0x%X", usbn_get_version());
   printf("\r\n\n");
  #endif


   while (TRUE) {
      usb_task();
      usb_debug_task();

      if (kbhit()) {
         c=getc();
         if (c=='\n') {usb_cdc_putc('\r'); usb_cdc_putc('\n');}
         if (c=='\r') {usb_cdc_putc('\r'); usb_cdc_putc('\n');}
         else {usb_cdc_putc(c);}
      }
      if (usb_cdc_kbhit()) {
         c=usb_cdc_getc();
         if (c=='\n') {putc('\r'); putc('\n');}
         if (c=='\r') {putc('\r'); putc('\n');}
         else {putc(c);}
      }
   }
}


I'm using a 20MHz crystal
johnlook1975
Guest







Problem with USB
PostPosted: Fri Sep 28, 2007 9:58 am     Reply with quote

I watch the Standard OpenHCD Root USB Controller in device manager it seens well, but my device don't appear in the list.
Ttelmah
Guest







PostPosted: Fri Sep 28, 2007 10:20 am     Reply with quote

The 'logic' of your line feed handling is wrong, but this shouldn't cause any problem for the USB. As it presently stands, if a '\n' is seen, it'll send '\r', then '\n', then still send the '\n' character. The 'else' only applies to the '\r' condition. I hink you want:
Code:

         if (c=='\n' || c=='\r') {usb_cdc_putc('\r'); usb_cdc_putc('\n');}
         else {usb_cdc_putc(c);}

and the same for the one on the normal serial.

It certainly appears that it should work.
Is the failure 'time' from when it first enumerates, or from when the first character is seen?. Have you got the connection sense pin wired as shown? (otherwise you need to disable this option).

Best Wishes
johnlook1975
Guest







Problem with USB
PostPosted: Mon Oct 01, 2007 1:51 pm     Reply with quote

I'm not using sense pin. I did every thing, but it still don't work.
ELCouz



Joined: 18 Jul 2007
Posts: 427
Location: Montreal,Quebec

View user's profile Send private message

PostPosted: Mon Oct 01, 2007 2:39 pm     Reply with quote

well, seriously usb is tricky to debug, since there no really feedback precise error code for it.

anyway you can try posting more info such as a schematic of your project.
in this way we could further help you in your project.

EDIT: check the vUSB pin voltage must be constant @ 3.3V
johnlook1975
Guest







Problem with USB
PostPosted: Mon Oct 01, 2007 5:34 pm     Reply with quote

I have the schematic of the project, but I don't know how to post it, can you explain ?
Guest








Re: Problem with USB
PostPosted: Mon Oct 01, 2007 6:06 pm     Reply with quote

johnlook1975 wrote:
I have the schematic of the project, but I don't know how to post it, can you explain ?

vUSB is at 1,0V
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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