|
|
View previous topic :: View next topic |
Author |
Message |
pablopaolus
Joined: 13 May 2012 Posts: 5 Location: SPAIN
|
PIC18F46J50 - USB device not recognised |
Posted: Wed Apr 24, 2013 4:33 am |
|
|
Hi all,
I'm having problems with PIC18F46J50 and USB, since ir gets stuck at usb_wait_for_enumeration(). Here's the part of my code related to USB operation:
Code: |
#include <18F46J50.h>
#device ADC=10;
#fuses NOWDT
#fuses NOPROTECT
#fuses DEBUG
#fuses HSPLL // According to page .41 datasheet
#fuses PLLDIV4 // External oscillator: 16 MHz. So PLL4 --> 16 MHz / 4 = 4 MHz
#fuses NOCPUDIV // According to page .41 datasheet
#use delay(clock=48000000)
#define USB_HID_DEVICE FALSE
#define USB_EP1_TX_ENABLE USB_ENABLE_BULK //EP1(EndPoint1) for IN bulk/interrupt transfers
#define USB_EP1_RX_ENABLE USB_ENABLE_BULK //EP1(EndPoint1) for OUT bulk/interrupt transfers
#define USB_EP1_TX_SIZE 32
#define USB_EP1_RX_SIZE 32
#include <pic18_usb.h> //Microchip PIC18Fxx5x Hardware layer for CCS's PIC USB driver
#include "usb_desc_scope.h" //device configuration descriptors
#include <usb.c> //handles usb setup tokens and get descriptor reports
.
.
.
usb_init();
usb_wait_for_enumeration(); //Gets stuck here
usb_task();
.
.
.
|
I've got Vusb conencted to ground through a 100nF capacitor. I've tried reversing D- and D+ connections (just in case they were wrong) with the same result.
Any help would be very much appreciated.
Thank you for reading. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9247 Location: Greensville,Ontario
|
|
Posted: Wed Apr 24, 2013 5:23 am |
|
|
I suggest you use the examples that CCS supplies in the 'examples' folder before you try your own code. I know that the CDC example does work on a '4550.
Once you've got their program running, then either copy/modify it ,or cut your own, but at least you'll have agret working example.
hth
jay |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Wed Apr 24, 2013 7:00 am |
|
|
Hi,
Are you sure the PIC is actually running? Are you sure it's running at the intended clock speed?
Every one of my PIC development efforts starts with the ubiquitous 'blinking LED' test. Even for 'cut-n-pasted' working code from other projects, this test tells me definitively that my new PIC project is operating, and operating at the intended speed. I recently had an issue where water-soluble flux residue was preventing the external crystal oscillator from starting, and the PIC was falling back to the internal oscillator. The blinking LED test alerted me that something was amiss before I wasted any more time!
Connect an LED to one of your PIC I/O pins thru a suitable current limiting resistor, and then toggle it repeatedly at a known rate, and see if it operates as expected. One second On, and one second Off is a pretty good test, and is easy to time without special equipment.
John |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Wed Apr 24, 2013 7:47 am |
|
|
First thing, you do realise that unlike the 4550, _you_ have to supply Vusb?. USB won't work without this connection.
On the 4550, there is an internal voltage regulator to supply this enabled by Vregen, and only the capacitor is needed. On this chip, you need an external source.
Best Wishes |
|
|
pablopaolus
Joined: 13 May 2012 Posts: 5 Location: SPAIN
|
|
Posted: Wed Apr 24, 2013 11:30 am |
|
|
Thank you all for your answers Let's see:
Ttelmah: Yes, I have supplied Vusb with 3.3V, and bypassed to ground through the 100nF capacitor. Also, I have the Vcap/Vddcore pin connected to a 10uF capacitor to ground (I don't know if this has to do with anything...)
ezflyr: I've also used the 'blinking LED' test, and I've checked that the PIC is running. However, thanks to you I've realised that it's not running at the intended clock speed... I'm lighting on and off every second according to my code, but in practice I can count as far as 3 seconds instead of 1. I don't understand where the error can be, since I'm using a 16Mhz external xtal oscillator and I think my fuses are correct, aren't they? Can this be directly related with USB bad working?
Thank you very much.
PS: Just in case you are wondering, I also have MCLR pin connected to 3.3V through a 10k resistor... I'm saying because this is the typical mistake (I've made it more than once...) |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Wed Apr 24, 2013 2:48 pm |
|
|
I've been running the 26J50, for a while.
Only differences, 12Mhz clock in, and using a crystal module rather than the crystal.
ECPLL, NOWDT, PLL3, NOXINST, NOCPUDIV, NOFCMEN, NOIESO, NOIOL1WAY, STVREN
I turned off all the 'fall back' stuff when originally I was testing, since this ensures you know that you are running from the external oscillator and not 'falling back' to the internal one. Also since I was doing a lot of peripheral configuration later in my code, 'NOIOL1WAY'.
I'd try:
HSPLL, NOWDT, PLL4, NOXINST, NOCPUDIV, NOFCMEN, NOIESO, NOIOL1WAY, STVREN
Without DEBUG, and 80% matching my working fuses. Then just do the timing test. This does need to be right before trying to get any further, or it'll cause problems later. What compiler version?.
Once this is working, make sure you have:
#define __USB_PIC_PERIF__ 1
Before loading the USB stuff. The code won't automatically detect this chip, so needs to be told to use the PIC USB. Might be the other problem (not sure if it defaults to this peripheral or not).
I'd also start with the standard CDC driver and get this working first.
Best Wishes |
|
|
pablopaolus
Joined: 13 May 2012 Posts: 5 Location: SPAIN
|
|
Posted: Thu Apr 25, 2013 6:02 am |
|
|
Ok, timing test is now properly working. This is what I've done:
1) I've changed my fuses as you have said, but timing test didn't still work.
2) Then I've added:
Code: | setup_oscillator(OSC_PLL_ON); |
at the first line of my main code, because on these chips the PLL is software controllable. I've been aware of this thanks to an old answer of yours in this thread :
http://www.ccsinfo.com/forum/viewtopic.php?t=47817
Now I'm going to struggle with USB... I'll try the standard CDC driver as you have suggested.
Thank you very much.
By the way, my compiler version is 4.104. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Thu Apr 25, 2013 8:02 am |
|
|
The compiler version is critical in this (why I asked). The PLL is automatically enabled by the software if you specify a clock rate that needs it with more modern compilers....
Best Wishes |
|
|
pablopaolus
Joined: 13 May 2012 Posts: 5 Location: SPAIN
|
|
Posted: Fri May 03, 2013 12:10 pm |
|
|
Hello again,
I come back... I've been working on USB CDC connection, which is driving me mad.
Sometimes it works: PIC appears as a virtual COM at Device Manager. I've even been able to communicate with a Labview application I've created. However, it suddenly disappears and disconnects, unable to find the driver. I've made hundreds of trials both in W7 and XP, with the same results. Sometimes PC recognised it... sometimes not... sometimes it seems it's not going to work, then it appears after a minute... then it disconnects...
Any idea, please?
Thank you very much. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri May 03, 2013 12:20 pm |
|
|
tried FTDI FT232 ??? |
|
|
|
|
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
|