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

USB CDC on PIC24FJ doesn't work
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
E_Blue



Joined: 13 Apr 2011
Posts: 406

View user's profile Send private message

PostPosted: Tue Nov 05, 2019 9:16 am     Reply with quote

Yes, even stack=0x400 and didn't work.
_________________
Electric Blue
E_Blue



Joined: 13 Apr 2011
Posts: 406

View user's profile Send private message

PostPosted: Wed Nov 06, 2019 9:35 am     Reply with quote

I just connected the Saleae logic analyzer and seems like the PIC24FJ is not responding.

https://drive.google.com/file/d/17p7am2kmMVILSMWyNAOVYAKiFQ5D7WtL/view?usp=sharing

Here the PICkit 3 sniff to compare.

https://drive.google.com/file/d/1362mYwZaSPH3iYnFnh9G6dYydNC3V8-3/view?usp=sharing
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Nov 07, 2019 2:11 am     Reply with quote

You are calling usb_init?.
Try a really basic code like the CCS serial example.
Go and 'triple check' the connections. In particular the polarity of D+ & D-
the only time I couldn't get a board to initialise I had fitted a 'R' connector
that had the pin order reversed (designed to mount on the back of the
board).
Is D+ being taken high when the device is plugged in?.
The header was taken from a working data logger.
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Nov 07, 2019 5:31 am     Reply with quote

re: In particular the polarity of D+ & D-
the only time I couldn't get a board to initialise I had fitted a 'R' connector
that had the pin order reversed (designed to mount on the back of the
board).

WOW, and I thought I was the ONLY one who had THAT happen to !! One of those 'worked in the morning,not in the afternoon when I 'cleaned up the rats nest' to stuff into a box'.
After that I bought USB-TTL modules, money well spent...no more USB 'issues'.

Jay
E_Blue



Joined: 13 Apr 2011
Posts: 406

View user's profile Send private message

PostPosted: Thu Nov 07, 2019 8:41 am     Reply with quote

The hardware seems to be ok because I just made a simple program with MPLAB Code Configurator (MCC) and runs ok; I got COM16.

The problem now is that my code is for CCS not XC16.

Before this I tried to get the USB Eye pattern with no luck.

Code:
#include <24FJ1024GB606.h>
#build(STACK=0x400)
#use delay(internal=32000000,USB_FULL, ACT=USB)

#bit UTEYE = getenv("BIT:UTEYE")
#bit USBEN = getenv("BIT:USBEN")
#bit USB1MD = getenv("BIT:USB1MD")
#bit DMPULUP = getenv("BIT:DMPULUP")
#bit DPPULUP = getenv("BIT:DPPULUP")
#bit USBPWR = getenv("BIT:USBPWR")

void main()
{   
    set_tris_g(0b11001001100);
    set_tris_f(0b10001000);
    UTEYE=1;
    USBEN=1;
    USB1MD=1;
    DMPULUP=1;
    DPPULUP=1;
    USBPWR=1;
   
    while(1)
    {
        output_toggle(PIN_D7);
        delay_ms(2);
    }
}



But when I halt the program the bits didn't get set.
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Nov 07, 2019 9:10 am     Reply with quote

Pulling up both lines is never legitimate in USB. A full speed device pulls up
D+, a low speed device D-.

The settings for EYE, are USBPWR=1, UTEYE=1, and SUSPEND=0.

USUSPND=0

Be aware the device should not be connected to a USB bus when this is set.
E_Blue



Joined: 13 Apr 2011
Posts: 406

View user's profile Send private message

PostPosted: Thu Nov 07, 2019 9:38 am     Reply with quote

I think CCS is setting up the fuses wrong
Check this is what CCS set up



This is XC16



Check FOSCSEL and FOSC 96MHz PLL is disabled and should be enabled and says PLL is fed by primary oscillator, that's completely wrong.

Also there's no option in 24FJ1024GB606.h file to set the 96MHz PLL on.

There's any way to set up config fuses by an hexadecimal?

Maybe something like

#fuses FOSCSEL 0xFFFF89
#fuses FOSC 0XFFFA7

Or with #pragma, I never used #pragma before.
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Nov 07, 2019 10:36 am     Reply with quote

Get rid of your USB_FULL setting. You will notice I don't use this. This is
specifically to configure the primary oscillator to support USB. By default
the code automatically sets to timings correctly, and this may be what is
actually stopping it working....
If you look in the example, the setting using ACT, does not use this setting.
E_Blue



Joined: 13 Apr 2011
Posts: 406

View user's profile Send private message

PostPosted: Fri Nov 08, 2019 6:27 am     Reply with quote

I already did it, same results.
I'm going to try to port the code to XC16
I can't believe that there's no way to set the fuses manually.
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Fri Nov 08, 2019 7:50 am     Reply with quote

Of course you can set the fuses manually.
Just set them.
Key thing though is to do it after the #use delay statement. This overrides
the fuses controlling the clock.

However I doubt if this is actually the problem. CCS by default always
wakes chips up with the PLL disabled, and then enables it at the start of
the code. This is done, because many PIC's do not support starting with the
PLL enabled, and even more have errata that apply when this is done.
Simpler and safer to always set the fuses to not enable it.

Going to try the experiment of compiling some test code for your chip
and compare with the same code compiled for the smaller chip. Most likely
thing is an error somewhere in the device database for your specific chip.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Fri Nov 08, 2019 8:01 am     Reply with quote

Just checked, and compiled this:
Code:

#include <24FJ1024GB606.h>
#fuses NOWDT //Needed
#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>

void main(void)
{
   usb_cdc_init();
 
   while (TRUE)
   {
      if (usb_cdc_kbhit())
         usb_cdc_putc(usb_cdc_getc());
      usb_task();
   }
}

One glaring problem. The watchdog is enabled.

Added #fuses NOWDT, and compiled again, and PLL2 is enabled.
Both with the current compiler and your version.

Have you been disabling the watchdog?. It won't work unless you do
the chip will be continuously resetting every couple of mSec.
E_Blue



Joined: 13 Apr 2011
Posts: 406

View user's profile Send private message

PostPosted: Fri Nov 08, 2019 8:04 am     Reply with quote

How I can set fuses manually if there no option; some PIC18 have a 96MHz PLL and the setup for the divider not the 24F1024GB606.

Code:
//////// Program memory: 352128x24  Data RAM: 32768  Stack: 31
//////// I/O: 52   Analog Pins: 16
//////// Fuses: WRTB,BSSHS,BSSSS,NOBSS,BS,WRT,PROTECT_HIGH,PROTECT,NOPROTECT
//////// Fuses: WPCFG,PROTECT_HIGH_CFG,PROTECT_ENH_CFG,PROTECT_CFG
//////// Fuses: NOPROTECT_CFG,AIVT,BSS,FRC,FRC_PLL,PR,PR_PLL,SOSC,LPRC,DCO
//////// Fuses: FRC_PS,PLL4X,PLL6X,PLL8X,NOPLL,IESO,EC,XT,HS,NOPR,OSCIO
//////// Fuses: SOSC_DIG,SOSC_SEL,PLL_FROM_FRC,PLL_FROM_PRIMARY,IOL1WAY
//////// Fuses: CKSFSM,CKSNOFSM,NOCKSNOFSM,WPOSTS1,WPOSTS2,WPOSTS3,WPOSTS4
//////// Fuses: WPOSTS5,WPOSTS6,WPOSTS7,WPOSTS8,WPOSTS9,WPOSTS10,WPOSTS11
//////// Fuses: WPOSTS12,WPOSTS13,WPOSTS14,WPOSTS15,WPOSTS16,WDT32,WDT128
//////// Fuses: NOWDT,WDT_NOSL,WDT_SW,WDT,WINDIS,WDTWIN_75%,WDTWIN_50%
//////// Fuses: WDTWIN_37%,WDTWIN_25%,WDTCMX,WDTCLK_SYS,WDTCLK_SOSC
//////// Fuses: WDTCLK_31KHZ,WDTCLK_LPRC,NOBROWNOUT,BROWNOUT_SW
//////// Fuses: BROWNOUT_NOSL,BROWNOUT,LVR,DNVP,ICSP3,ICSP2,ICSP1,JTAG,DEBUG
//////// Fuses: BTSWP,ALTCMPI,TMPRPIN,SOSC_LOW,SOSC_HIGH,VREFALT_CVREFALT
//////// Fuses: VREFNORM_CVREFNORM
////////

_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Fri Nov 08, 2019 8:09 am     Reply with quote

Read the manual.

You can set any fuse word by number.

#fuses 2 = 0xCC55AA

sets fuse word 2 to 0xCC55AA

Just looked at the listing, and the value you are showing your compiler
as generating FFFFFF9, is not what the compiler generates for the fuses
given.

The PLLn settings control the divider.
Every fuse the chip has can be set using the CCS values. However your
compiler is old enough to lack some:

Code:

//////// Fuses: WRTB,NOWRTB,BSSHS,BSSSS,NOBSS,BS,NOBS,WRT,NOWRT,PROTECT_HIGH
//////// Fuses: PROTECT,NOPROTECT,WPCFG,NOWPCFG,PROTECT_HIGH_CFG
//////// Fuses: PROTECT_ENH_CFG,PROTECT_CFG,NOPROTECT_CFG,AIVT,NOAIVT,BSS
//////// Fuses: FRC,FRC_PLL,PR,PR_PLL,SOSC,LPRC,DCO,FRC_PS,PLL1,PLL2,PLL3
//////// Fuses: PLL4,PLL5,PLL6,PLL5,PLL12,PLL4X,PLL6X,PLL8X,NOPLL,NOIESO
//////// Fuses: IESO,EC,XT,HS,NOPR,OSCIO,NOOSCIO,SOSC_DIG,SOSC_SEL
//////// Fuses: PLL_FROM_FRC,PLL_FROM_PRIMARY,NOIOL1WAY,IOL1WAY,CKSFSM
//////// Fuses: CKSNOFSM,NOCKSNOFSM,WPOSTS1,WPOSTS2,WPOSTS3,WPOSTS4,WPOSTS5
//////// Fuses: WPOSTS6,WPOSTS7,WPOSTS8,WPOSTS9,WPOSTS10,WPOSTS11,WPOSTS12
//////// Fuses: WPOSTS13,WPOSTS14,WPOSTS15,WPOSTS16,WDT32,WDT128,NOWDT
//////// Fuses: WDT_NOSL,WDT_SW,WDT,NOWINDIS,WINDIS,WDTWIN_75%,WDTWIN_50%
//////// Fuses: WDTWIN_37%,WDTWIN_25%,NOWDTCMX,WDTCMX,WDTCLK_SYS,WDTCLK_SOSC
//////// Fuses: WDTCLK_31KHZ,WDTCLK_LPRC,NOBROWNOUT,BROWNOUT_SW
//////// Fuses: BROWNOUT_NOSL,BROWNOUT,LVR,NOLVR,NODNVP,DNVP,ICSP3,ICSP2
//////// Fuses: ICSP1,NOJTAG,JTAG,DEBUG,NODEBUG,BTSWP,NOBTSWP,ALTCMPI
//////// Fuses: NOALTCMPI,TMPRPIN,NOTMPRPIN,SOSC_LOW,SOSC_HIGH
//////// Fuses: VREFALT_CVREFALT,VREFNORM_CVREFNORM


These were fixed at about 5.080.[/code]


Last edited by Ttelmah on Fri Nov 08, 2019 8:26 am; edited 1 time in total
E_Blue



Joined: 13 Apr 2011
Posts: 406

View user's profile Send private message

PostPosted: Fri Nov 08, 2019 8:26 am     Reply with quote

Already did it, only works with fuses 1
Also must be no space next to the '='

Compiles ok
Code:
#fuses 2=0xCC55AA;


Error at compile time
Code:
#fuses 2 = 0xCC55AA;


Anyways, it doesn't change any fuse beyond the first one

Your last program do nothing.
If I use
Code:
#define USB_CON_SENSE_PIN PIN_F7

At least I get the unknown device balloon.
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Fri Nov 08, 2019 8:34 am     Reply with quote

Seriously, merrily works for me, using your compiler version:
Code:

#include <24FJ1024GB606.h>
#fuses NOWDT

#use delay(internal=32MHz, ACT)


Generates:
Code:

   Word  7L: FF89   FRC_PLL PLL2 IESO
          H: 0000


Then instead compile with:
Code:

#include <24FJ1024GB606.h>
#fuses NOWDT

#use delay(internal=32MHz, ACT)
#fuses 7=0x0000 //test to see if fuses change


and merrily generates:
Code:

   Word  7L: 0000   FRC PLL1 NOIESO
          H: 0000 


As you can see it has left it's own 'fuse comments', but has changed the
word to 0000.
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 Previous  1, 2
Page 2 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