View previous topic :: View next topic |
Author |
Message |
biozit
Joined: 31 Dec 2010 Posts: 3 Location: BR
|
usb_init() problem |
Posted: Sun Oct 23, 2011 10:31 am |
|
|
Hi all,
I am trying to use the the PIC18f4550 to produce a virtual com port.
The code is:
main.c
Code: |
#include <main.h>
#include <usb_cdc.h>
void main()
{
output_high(PIN_B0);
usb_cdc_init();
usb_init();
while(!usb_cdc_connected()) {}
while(true)
{
output_high(PIN_B1);
usb_task();
if (usb_enumerated()) {
printf(usb_cdc_putc, "ola");
}
output_high(PIN_B2);
}
}
|
main.h
Code: |
#include <18F4550.h>
#device adc=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES PLL1 //No PLL PreScaler
//#FUSES CPUDIV2 //System Clock by 2
//#FUSES INTRC //Internal RC Osc
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(crystal=4000000)
|
But just the PIN_B0 go high and the windows don't recognize the serial port.
Has any error in the code ? Could be hardware ? ( I am using a breadboard ) |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Sun Oct 23, 2011 12:46 pm |
|
|
You're best to use the example in the examples folder first before you go 'out on your own'.
I currently have a breadboarded PIC18F4550 running at 48MHz without any problems.
I'm running windows XP PRO and once the driver was installed( the dotINF file) Windows was happy...
also be sure that D+ and D- are correct. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Sun Oct 23, 2011 2:46 pm |
|
|
and that Vusb is properly smoothed.
Big one though. the fuses are not there to turn on the USB Vreg, and select the USB clock source. Otherwise USB is not going to work, unless you feed 3.3vv to Vusb.
You need USBDIV, and VREGEN in the fuses to have any hope.
It should then be seen.
However 4MHz as the CPU clock, is 'pushing it'. You may well find that you will have problems with this. 8MHz is probably OK, but in the past, dropping the frequency 'too low', gives unreliable operation, and 4MHz falls into this area.
There is also a 'caveat', that the PLL, can sometimes be unreliable off 4Mhz crystals, being very critical on drive levels. 8MHz is much safer, or you may have to add a series resistor to get reliable operation.
Remember you can run the USB off the crystal, and the CPU off the internal RC at 8Mhz if required.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
biozit
Joined: 31 Dec 2010 Posts: 3 Location: BR
|
|
Posted: Sun Oct 23, 2011 4:07 pm |
|
|
Thanks for the help Ttelmah and temtronic,
I checked the D+ and D-.
Now i trying with a crystal 26 Mhz and the example ex_usb_serial2.c.
What you mean smoothed Vusb ? i put a capacitor with 470 nf in the Vusb, is that correct ? |
|
![](templates/subSilver/images/spacer.gif) |
|