View previous topic :: View next topic |
Author |
Message |
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
USB CDC on PIC24FJ doesn't work |
Posted: Fri Nov 01, 2019 9:43 am |
|
|
Device PIC24FJ1024GB606
CCS: V5.078
I can't get USB enumerated; I think is something related to USB_SENSE?
First I tried with
Code: | #define USB_CON_SENSE_PIN PIN_F7 |
And didn't work because the RF7 pin control seems to be taken by USB logic and the program can't see the current pin state; so I changed the definition to
Code: | #bit U1OTGSTAT_VBUSVD=getenv("BIT:VBUSVD")
#define USB_CABLE_IS_ATTACHED() (U1OTGSTAT_VBUSVD) |
But didn't work either.
I suspect that happen because that work only if the USB logic is in OTG mode.
I also read that there's a bit that can change the RF7 behavior with UVCMPDIS bit; but I'm no sure if I will mess up the CCS code if I change this "manually".
Currently I have VUSB/RF7 pin wired to USB 5V connector through a 100ohm resistor and a 10K resistor to GND.
I read this post with some similar problem.
http://www.ccsinfo.com/forum/viewtopic.php?t=52758
Now I'm wondering if I change the USB logic configuration to OTG mode can run as CDC device, that's the only I need. _________________ Electric Blue |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Fri Nov 01, 2019 1:32 pm |
|
|
How is your chip powered?. USB power or it's own power?.
Have you got Vusb 3.3 connected?. Needs regulated 3.3v. If you are
running off the USB supply, you need a LDO to power the PIC and this
pin. If you have your own power this should be fed from this.
The 5v from the USB bus does go to RF7, but must have a 100R resistor
in line. There should also be a 100K resistor pulling the line to GND so
that it will go low whwn the bus is disconnected (except when ypu are using
USB power).
How is your clock generated?. Internal or USB sync?. If the latter this
needs to be specified in the clock setup (ACT=USB). The clock will
not be accurate enough for enumeration unless this is done. |
|
|
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
|
Posted: Fri Nov 01, 2019 2:36 pm |
|
|
The device has its own power supply from 12V with a DC-DC to get 4.6V then a 3.3V LDO to supply the PIC VDD, AVDD and VUSB.
Yes, the 100R is connected to the 5VUSB connector, also has a 10K resistor from 5VUSB to GND.
Maybe is the clock; I have:
Code: | #use delay(internal=32MHz, USB_FULL) |
I didn't know about ACT. _________________ Electric Blue |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Sat Nov 02, 2019 12:03 am |
|
|
You absolutely must have ACT. USB requires a clock that has to be
accurate to 1 part in 50000. The internal oscillator is only accurate to
a couple of percent.....
For USB.
Table 9.3 in the data sheet:
Quote: |
2: This requires the use of the FRC self-tune feature
to maintain the required clock accuracy
|
|
|
|
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
|
Posted: Sat Nov 02, 2019 9:04 am |
|
|
I currently have a PIC18F67J50 running on it's own internal clock and the USB works ok.
The PIC24FJ project is an upgrade to the same product, so the internal code is pretty the same.
What did change in PIC24FJ devices? The internal clock is worse? _________________ Electric Blue |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sat Nov 02, 2019 9:33 am |
|
|
It seems every PIC family and sub-family or variants have 'minor' differences so reading the datasheet is critical, especially for ANY area where 'timing' is important.
Once you get into the 'powerhouse' PICs like 24 and 32 series you also need to consider how local heating affects clock speeds. Some PICs have 'tighter' and more accurate clocks, but for any serious 'Real World' use, I suggest an external xtal and caps.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Sat Nov 02, 2019 11:40 am |
|
|
You should not be able to get 'USB_FULL' to run on any PIC's internal
clock without ACT. Low speed USB, a couple are good enough to do.
What speed are you running the USB on the older chip?.
Like anything though the clock in some cases at specific temperatures
and voltages 'may' be good enough sometimes.
On your old chip, the internal oscillator is specifically rated to support
low speed USB. The new chip is not.
Just turn on ACT. Costs you nothing and gives it a chance.
If your master oscillator frequency on the old chip is 24MHz, then you
are using low speed USB. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Sun Nov 03, 2019 3:40 am |
|
|
Just checked some old code of mine, and you are testing the wrong bit
for the connection sense. Mine is:
Code: |
#bit U1OTGSTAT_SESVD=getenv("BIT:SESVD")
#define USB_CABLE_IS_ATTACHED() (U1OTGSTAT_SESVD) //cable attached for DsPIC
|
Must admit this is very unclear in the data sheets, but the VBUSVD bit
is only for when the VBUS is being developed by the internal inverter
in USB OTG mode. Only for an 'A' device.
The SESVD bit (though it refers to 'session', is specified as:
"The VBUS voltage is above VA_SESS_VLD (as defined in the USB OTG
Specification) on the A or B-device",
and is valid for both a host and slave (A or B) device..... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sun Nov 03, 2019 6:03 am |
|
|
gee Mr. T. one day your head's going to explode and we'll ALL lose your extensive PIC knowledge !!
How you can retain it all is beyond me....but I, like others, appreciate your dedication to a small slice of silicon !!
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Sun Nov 03, 2019 6:29 am |
|
|
My speciality, is "wall, head, impact technology testing". Seem to
spend many days doing this!....
I remember having issues on the OTG PIC's finding the right bit for
the voltage sense, so went looking back to see what I found.
I try always to document things like this, so have comments saying
what I found. Absolutely essential, since it is amazingly difficult to
remember this sort of thing if you don't touch it for a few months.
So I'd say the key is tens of thousands of comments, rather than my
brain!. |
|
|
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
|
Posted: Mon Nov 04, 2019 1:35 pm |
|
|
I change the code to
Code: | #include <24FJ1024GB606.h>
#use delay(internal=32MHz, USB_FULL,ACT)
#define __USB_PIC_PERIF__ 1
#bit U1OTGSTAT_SESVD=getenv("BIT:SESVD")
#define USB_CABLE_IS_ATTACHED() (U1OTGSTAT_SESVD) //cable attached for DsPIC
#include <usb_cdc.h>
#include <pic24_usb.h> |
Now I don't get the Windows warning balloon, its like there's nothing connected.
I have 4.73V on RF7 when USB is connected and 0.00V when is disconnected. _________________ Electric Blue |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Mon Nov 04, 2019 11:07 pm |
|
|
The syntax for ACT, is ACT=USB. This tells the tuning what device
it is to synchronise 'to'. The clock tuning can run off several things. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Tue Nov 05, 2019 12:55 am |
|
|
This is direct code from the 512K version of the same chip. Works:
Code: |
#build(STACK=0x400)
#use delay(internal=32000000, ACT=USB)
#bit VBUSVD = getenv("BIT:VBUSVD")
#if defined(USB_CABLE_IS_ATTACHED)
#undef USB_CABLE_IS_ATTACHED
#endif
#define USB_CABLE_IS_ATTACHED() (VBUSVD==1)
#include <usb_cdc.h>
|
If you look, key thing is that the 'is attached' define has to include the
actual test in it. Not just the pin define. |
|
|
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
|
Posted: Tue Nov 05, 2019 8:26 am |
|
|
The USB_CABLE_IS_ATTACHED() didn't work I don't get even the warning balloon.
I changed to
Code: | #define USB_CON_SENSE_PIN PIN_F7 |
And at least I get the warning balloon.
Anyway, I think there's something wrong with the clock definition maybe the USB PLL is not properly set up.
I'm calling usb_stack() every 5ms by interrupt and is working ok I checked up by toggling a pin and it changes every 5.05mS so the core is running at 32MHz But the USB?. _________________ Electric Blue |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Tue Nov 05, 2019 8:42 am |
|
|
Have you tried actually setting everything up as I show. Clock and
sense pin?. That is running OK on a PIC24FJ512GB606. _Working_.
I also did that code a long while back and it ran then and still runs
now. Just checked and it was first built 16/05/2017, compiler was
5.073. Was rebuilt only a few weeks ago on 5.080. You don't want/need
the 'USB_FULL' setting. The driver does this automatically. |
|
|
|