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

18F2550 USB not working

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



Joined: 24 Apr 2010
Posts: 10

View user's profile Send private message Visit poster's website

18F2550 USB not working
PostPosted: Sun Apr 25, 2010 10:48 pm     Reply with quote

Hi! I'm trying to connect my pic with my computer using the USB port. When I connect it, I get the following error:
Quote:

USB Device not Recognized. One of the USB devices attached to this computer has malfunctioned, and Windows does not recognize it.

I'm using the following code:
Code:

#include <18F2550.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC                    //Internal RC Osc INTRC
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT               //No brownout reset NOBROWNOUT
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES PUT                    //No Power Up Timer NOPUT
#FUSES NOCPD                    //No EE protection
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
#FUSES PBADEN                   //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC                   //configuration not registers write protected
#FUSES NOWRTB                   //Boot block not write protected
#FUSES NOEBTR                   //Memory not protected from table reads
#FUSES NOEBTRB                  //Boot block not protected from table reads
#FUSES NOCPB                    //No Boot Block code protection
#FUSES MCLR                     //Master Clear pin enabled
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES XINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode) NOXINST
#FUSES PLL5                    //Divide By 12(48MHz oscillator input) PLL12
#FUSES CPUDIV1                  //System Clock by 4 CPUDIV4
#FUSES USBDIV                   //USB clock source comes from PLL divide by 2
#FUSES VREGEN                   //USB voltage regulator enabled

#include <usb_cdc.h>

#use delay(clock=48000000)

void main()
{
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   
   output_high(PIN_C1);
   
   // USB Port
   
   usb_cdc_init();
   usb_init();
   usb_task();
   if (usb_enumerated()) {
      delay_ms(50);
      printf(usb_cdc_putc,"\rHeeeeello!");
   }

}

And the following circuit, with internal oscillator:

What could be wrong? Shocked
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 26, 2010 1:17 am     Reply with quote

Quote:
#FUSES INTRC

You're trying to run the USB module from the internal oscillator.
Download the 18F2550 data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39632e.pdf
Look at the block diagram of the 18F2550 oscillator on page 26.
I don't see any connection between the Internal Oscillator Block
and the USB Oscillator section. For comparison, look at the
18F26J50 data sheet. It does show a connection between the
internal oscillator and the USB section.

The standard way that all the CCS examples do it, is to use an
external 20 MHz crystal (with 22 pf caps). This is divided down
by 5 (with the PLL5 fuse) to create the 4 MHz input clock required
by the USB PLL section.


Quote:
#FUSES XINST

Here you're using the Extended Instruction set mode. But CCS doesn't
support it, and enabling it will crash the program. Change it to NOXINST.
Ttelmah



Joined: 11 Mar 2010
Posts: 19447

View user's profile Send private message

PostPosted: Mon Apr 26, 2010 4:37 am     Reply with quote

Even on the 46/26J, there is a 'caveat', that you can only run the USB at low speed on the internal oscillator. For high speed operation, the oscillator doesn't meet the USB timing requirements...
The oscillator in the 4550, doesn't even get close, hence the lack of connection.

Best Wishes
kiewic



Joined: 24 Apr 2010
Posts: 10

View user's profile Send private message Visit poster's website

PostPosted: Tue Apr 27, 2010 8:58 pm     Reply with quote

I went to the electronics store and bought a crystal oscillator of 20 MHz and now everything works perfectly!


Thank you very much for your help. I thought the internal oscillator was fully equal to an external oscillator.
Renjith_Beginow



Joined: 21 May 2014
Posts: 12

View user's profile Send private message

PostPosted: Wed May 21, 2014 5:37 am     Reply with quote

Hiii,
I am using 18F26J50, and i am trying implement USB, but its showing the device not recognized,
Can any one help with a working code and oscillator configuration, i think my oscs configuration is creating pblm
Ttelmah



Joined: 11 Mar 2010
Posts: 19447

View user's profile Send private message

PostPosted: Wed May 21, 2014 8:51 am     Reply with quote

#FUSES HSPLL, NOWDT, PLL3, NOXINST, NOCPUDIV, NOFCMEN, NOIESO, NOIOL1WAY

With a 12MHz crystal. CLOCK=48MHz.

Remember key differences on this chip, no USB regulator, so you need an external source of 3 to 3.6v fed into the Vusb pin. The chip can run off 2.35v to 3.6v, so simplest is to run off 3.3v, and connect Vusb to this as well.
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