|
|
View previous topic :: View next topic |
Author |
Message |
NWilson
Joined: 30 Jun 2011 Posts: 21 Location: King's Lynn. England
|
PIC24 - USB Device Not Recognized |
Posted: Mon Aug 18, 2014 7:28 am |
|
|
Device PIC24FJ128GC006
PCD 5.026
Hi All,
Saw this device advertised a few months back and thought it would be ideal for my next project as it contains many peripheral's like, USB, Op-Amps, DAC's, and a 16 bit ADC that I would like to use.
Anyway I've built a development PCB to test the device, but when I plug my test board into my PC, I get 'USB Device Not Recognised'
Test Code.
Code: |
//*****************************************************************
// 24FJ128GC006 USB Test PCB
// Jig.c
// Rev : 1.00
// Start Date : 18th Aug 2014
// Authors : Neil Wilson
//*****************************************************************
#include <24FJ128GC006.h>
#device ADC=16
#device ICSP=2
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#use delay(crystal=24000000,USB_FULL)
#case
#include <usb_cdc.h>
#include <Flex_lcd.h>
int1 usb_cdc_oldconnected=FALSE;
#define DISP_POWER PIN_E0
#define USB_CABLE_IS_ATTACHED() TRUE
void main()
{
output_high(DISP_POWER); // Apply power to the display
lcd_init(); // Initialise the display
printf(lcd_putc,"\fHello"); // Test Display - This works OK
usb_init_cs();
do {
usb_task();
if (usb_enumerated()){
if (usb_cdc_carrier.dte_present){
if (usb_cdc_oldconnected==FALSE){
printf(usb_cdc_putc,"Your 'connected' message");
lcd_gotoxy(1,2);
printf(lcd_putc,"Connected");
usb_cdc_oldconnected=TRUE;
}
//Do something
}
else
usb_cdc_oldconnected=FALSE;
}
else
usb_cdc_oldconnected=FALSE;
} while (TRUE);
} |
Has anyone successfully managed to get this pic working?
If so, could they please point me in the right direction.
Many thanks
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Mon Aug 18, 2014 8:16 am |
|
|
hmm...did you install the USB dotINF files onto the PC ?
I don't use the 24 series but in the USB driver files for the 18F4550 USB stuff there's a few comments about what's needed to get 'Windows' to recognize a PIC/USB device.
'silly thing' are D+,D- wired correctly ?
hth
jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Mon Aug 18, 2014 8:22 am |
|
|
Start with USB.
USB, when attached to a device that has it's own power _requires_ (not optional), cable attached detection. You are disabling this.
This is in the chip's data sheet:
"To meet compliance specifications, the USB module
(and the D+ or D- pull-up resistor) should not be enabled
until the host actively drives VBUS high. One of the 5.5V
tolerant I/O pins may be used for this purpose."
Then look at the chip.
Have you followed/met the section 2.1 connection requirements?.
Then I would specify a clock speed. It's a bit borderline whether the setup as posted can work. Basically you can only use 'crystal=xxx', if you are not using the PLL. However the USB _requires_ the PLL. |
|
|
NWilson
Joined: 30 Jun 2011 Posts: 21 Location: King's Lynn. England
|
|
Posted: Mon Aug 18, 2014 8:34 am |
|
|
Hi temtronic,
Thanks for the quick reply.
My Development PCB appears as an 'Unknown Device' under the device manager. Also, I've tried to update the driver with 'cdc_NTXPVista78.inf' to no avail.
Scoped D+ and D- and both appear OK and correctly wired. Not sure what's going on at the moment, I've used the PIC18F46J50 with similar code in the past and not had this problem.
Regards Neil |
|
|
NWilson
Joined: 30 Jun 2011 Posts: 21 Location: King's Lynn. England
|
|
Posted: Mon Aug 18, 2014 8:47 am |
|
|
Hi Ttelmah,
I based my circuit on Fig 19-3 of the data sheet (Page 267) and everything else is as in Fig 2.1 (page 33).
I'll try connecting VBUS to one of the 5V tolerant pins and enable the cable attached in code and see if that works.
Many thanks
Neil |
|
|
NWilson
Joined: 30 Jun 2011 Posts: 21 Location: King's Lynn. England
|
|
Posted: Tue Aug 19, 2014 6:17 am |
|
|
Hi All,
Many thanks for the help so far.
I've added the cable attached detection and changed the #fuses as suggested, however my problem still persists.
It seems that usb_enumerated() always returns FALSE.
Code: |
//*****************************************************************
// 24FJ128GC006 USB Test PCB
// Jig.c
// Rev : 1.00
// Start Date : 18th Aug 2014
// Authors : Neil Wilson
//*****************************************************************
#include <24FJ128GC006.h>
#device ADC=16
#device ICSP=2
#use delay(crystal=24000000, USB_FULL)
#FUSES NOWDT // No Watch Dog Timer
#FUSES NOJTAG// JTAG disabled
#FUSES HS // High speed Osc (>10mhz for PCD)
#FUSES PR_PLL // Primary Oscillator with PLL
#FUSES PLL6 // Divide By 6(24MHz oscillator input)
#case
#define DISP_POWER PIN_E0
#define USB_CON_SENSE_PIN PIN_E1
#define TELL_TAIL PIN_E2
#define PIN_USB_SENSE USB_CON_SENSE_PIN
#define USB_CABLE_IS_ATTACHED() input(PIN_USB_SENSE)
#include <usb_cdc.h>
#include <Flex_lcd.h>
int1 usb_cdc_oldconnected=FALSE;
void main()
{
output_high(DISP_POWER); // Apply power to the display
output_low(TELL_TAIL);
lcd_init(); // Initialise the display
printf(lcd_putc,"\fHello"); // Test Display - This works OK
usb_init_cs();
do {
if (usb_attached()){ // USB now attaches correctly
usb_task();
if (usb_enumerated()){ // Never seems to enumerate
output_high(TELL_TAIL);
output_low(TELL_TAIL);
if (usb_cdc_carrier.dte_present){
if (usb_cdc_oldconnected==FALSE){
printf(usb_cdc_putc,"Connected");
usb_cdc_oldconnected=TRUE;
}
//Do something
}
else
usb_cdc_oldconnected=FALSE;
}
else
usb_cdc_oldconnected=FALSE;
}
else
usb_cdc_init(); //clear buffers if disconnected
} while (TRUE);
} |
After much head scratching I'm not sure how to proceed. Any idea's |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Tue Aug 19, 2014 8:53 am |
|
|
OK.
I would do the attached the standard way. All you need to do, is :
Code: |
#define USB_CON_SENSE_PIN PIN_E1
#define __USB_PIC_PERIF__ 1 //This ensures the code selects the peripheral
#include <usb_cdc.h>
|
and the compiler will generate 'usb_attached' for you, using this pin.
This forces the code to use the PIC hardware, even if the chip is not one it recognises as having USB.
Have you actually got Vusb, connected to both Vbus, and to E1?.
Then the next obvious question, is whether the code is correctly configuring the USB as a standard slave.
In common with several other newer chips, this is one supporting USB 'on the go', so the peripheral has to be configured to use it like this. By default the PIC24 code should clear the U1CON register, before writing the bits it wants, which therefore should leave 'HOSTEN' (U1CON.3) turned off, and the peripheral setup as the normal USB peripheral.
Can you do a debug halt after the peripheral is configured, and verify that this is the case?.
Then, have you verified that the chip is actually running at the speed programmed (standard flash an LED test, or just write numbers one per second to the LCD, and verify these are incrementing every second)?.
I haven't tried this particular chip, but the driver works OK, on a couple of other 'close brethren', so I'd be triple checking everything. Silly things like D+, and D- being the opposite way round on the plug to what you expect, can be really annoying!...
I bought a different make of USB board connector, only to discover the manufacturer had done them for a 'special order', and crossed over D+, and D- internally. Aargh. |
|
|
NWilson
Joined: 30 Jun 2011 Posts: 21 Location: King's Lynn. England
|
|
Posted: Tue Aug 19, 2014 9:37 am |
|
|
Hi Ttelmah,
Thanks for replying, I've just tried the standard way and it made no difference.
Triple checked D+, D-, Vbus and E1 and all OK.
The chip seems to be running at the correct speed as toggling the 'Tell Tail' with delay_us(10) gives a 10uS pulse.
Was wondering whether OTG was the problem, but couldn't work out how to configure it as a slave, so I will debug it tomorrow and see if the registers you mentioned have been set.
Hopefully I can fix this problem and mark it as solved.
Once again, many thanks for you help.
Regards Neil |
|
|
NWilson
Joined: 30 Jun 2011 Posts: 21 Location: King's Lynn. England
|
|
Posted: Wed Aug 20, 2014 7:51 am |
|
|
OK.
Still no joy. Stepping through the code I found the following registers had changed:
breaking after usb_init_cs(); gave
U1CON = 0b01000010
U1IR = 0b00000001
U1OTGCON = 0b10000000
U1PWRC = 0b10000001
U1IE = 0b00000000
breaking after usb_attached() { gave
U1CON = 0b01000010
U1IR = 0b00000001
U1OTGCON = 0b10000000
U1PWRC = 0b00000001
U1IE = 0b00000000
and finally after usb_task();
U1CON = 0b01000011
U1IR = 0b00000000
U1OTGCON = 0b10000000
U1PWRC = 0b10000001
U1IE = 0b00010001
It appears that 'HOSTEN' (U1CON.3) is '0' I.E. device mode and not host mode.
Code: |
//*****************************************************************
// 24FJ128GC006 USB Test PCB
// Jig.c
// Rev : 1.00
// Start Date : 18th Aug 2014
// Authors : Neil Wilson
//*****************************************************************
#include <24FJ128GC006.h>
#device ICD=TRUE
#device ADC=16
#device ICSP=2
#use delay(crystal=24000000, USB_FULL)
#FUSES HS // High speed Osc (>10mhz for PCD)
#FUSES PR_PLL // Primary Oscillator with PLL
#FUSES PLL6 // Divide By 6(24MHz oscillator input)
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#case
#bit U1OTGSTAT_SESVD=getenv ("BIT:SESVD") //look at the SFR bit U1OTGSTAT.SESVD to determine if USB is connected.
#define USB_CABLE_IS_ATTACHED() (U1OTGSTAT_SESVD)
#define DISP_POWER PIN_E0
#define TELL_TAIL PIN_E2
#include <usb_cdc.h>
#include <Flex_lcd.h>
int1 usb_cdc_oldconnected=FALSE;
void main()
{
output_high(DISP_POWER); // Apply power to the display
output_low(TELL_TAIL);
lcd_init(); // Initialise the display
printf(lcd_putc,"\fHello"); // Test LCD Display - This works OK
usb_init_cs(); //Initializes the USB stack, run even if it's not connected to USB
while (TRUE)
{
if (usb_attached()){
output_high(TELL_TAIL); // 1uS pulse, USB Attached
delay_us(1);
output_low(TELL_TAIL);
usb_task();
if (usb_enumerated()){ // Never seems to enumerate
if (usb_cdc_carrier.dte_present){
if (usb_cdc_oldconnected==FALSE){
printf(usb_cdc_putc,"Connected");
usb_cdc_oldconnected=TRUE;
}
//Do something here
}
else
usb_cdc_oldconnected=FALSE;
}
else
usb_cdc_oldconnected=FALSE;
}
else
usb_cdc_init(); //clear buffers if disconnected
}
}
|
Here is the code that I have so far, still pulling my hair out! |
|
|
NWilson
Joined: 30 Jun 2011 Posts: 21 Location: King's Lynn. England
|
|
Posted: Tue Sep 09, 2014 3:19 am |
|
|
Been a few weeks now since I last tackled the USB on this chip.
Just wondering if anyone has got it going yet? |
|
|
drolleman
Joined: 03 Feb 2011 Posts: 116
|
|
Posted: Sat Sep 13, 2014 6:54 pm |
|
|
First do you have a device in device manager? This has to be there before a driver can be assigned to it. It may be yellow flagged, this means the there is no driver for it. Look in the properties of the yellow flagged device for the pid/vid and compare it to the inf file. If these don't match it won't work. Alter the inf file so they do match.
good luck |
|
|
juliogtd
Joined: 01 Jan 2009 Posts: 6
|
|
Posted: Mon Oct 27, 2014 1:47 am |
|
|
I think there must be something inherent to 24FJ128GC006 that we are ignoring. For example, the following code perfectly works with 24FJ256GB106 (PC recognizes the USB as a serial port).
Code: | #include <24FJ256GB106.h>
#fuses NOWDT, FRC, FRC_PLL, PLL1
#use delay(clock=32M,USB_FULL, act=USB)
#include <usb_cdc.h>
void main(){
usb_cdc_init();
usb_init_cs();
do{
if (usb_attached()){
usb_task();
if(usb_enumerated()){
}
}
}while(true);
} |
However, replacing <24FJ256GB106.h> by <24FJ128GC006.h> (and pin-compatible microcontrollers too, of course) no longer works.
MPLABX code (for the starter kit for intelligent.integrated.analog - 24FJ128GC010 based) works correctly.
One difference I see in the code is that the "USB module" is activated (_USBMD = 0)... could be that command the difference between work or not?
Code: | int main() {
_NSTDIS = 1; // Disable nested interrupts
//Initliaze USB //Enable interrupts
_USB1IF = 0; //Interrupt Flag Status bit 1 = Interrupt request has occurred
_USB1IP = 5; //Interrupt Priority bits 000..111 (highest priority interrupt)
_USB1IE = 1; //1 = Interrupt request is enabled
USBDeviceInit();
_USBMD = 0; //0 = Peripheral Module is "not" Disable
while (1) {
if (USBGetDeviceState() == DETACHED_STATE)
{
USBDeviceAttach();
}
CDCTxService();
}
return 0;
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Mon Oct 27, 2014 4:02 am |
|
|
By default the CCS code enables the USB port when init is called.
As already said, the obvious thing is the OTG configuration. Though this is meant to default to device mode, rather than host mode, the obvious thing to do, is manually ensure the bits for this are set. So:
Code: |
#bit OTGEN=getenv("BIT:OTGEN")
#bit USBEN=getenv("BIT:USBEN")
#bit USBPWR=getenv("BIT:USBPWR")
#bit DPPULUP=getenv("BIT:DPPULUP")
OTGEN=FALSE;
USBEN=TRUE;
USBPWR=TRUE;
DPPULLUP=TRUE;
usb_init;
|
|
|
|
juliogtd
Joined: 01 Jan 2009 Posts: 6
|
|
Posted: Mon Oct 27, 2014 10:49 am |
|
|
Ttelmah: You're right, the solution to the problem is not activating the USB module (I've confirmed, activating it manually). But neither is the OTG configuration: I tried your suggestion and it does not work.
It's something else. |
|
|
juliogtd
Joined: 01 Jan 2009 Posts: 6
|
|
Posted: Sat Mar 21, 2015 1:49 pm |
|
|
Hello, I keep thinking about why the USB 24FJ128GC006 not work with the CCS compiler.
In order to discover the reason, I followed the following steps:
1. I mounted two identical printed circuit boards, one with the PIC24FJ256GB106 and other with the PIC24FJ128GC006 (see photo).
2. I have programmed both microcontrollers with the same code, which is the minimum one so that, when connected to the USB port of PC, it recognizes that connected a virtual serial device (the PIC24FJ256GB106 works correctly and PIC24FJ128GC006 does not work. See the screenshots 1 and 2. I used "USBlyzer" software to confirm the communication).
Code: |
#include <24FJ256GB106.h>
#fuses NOWDT, FRC, FRC_PLL, PLL1
#use delay(clock=32M,USB_FULL, act=USB)
#include <usb_cdc.h>
void main(){
usb_init_cs();
usb_task();
}
|
Code: |
#include <24FJ128GC006.h>
#fuses NOWDT, FRC, FRC_PLL, PLL1
#use delay(clock=32M,USB_FULL, act=USB)
#include <usb_cdc.h>
void main(){
usb_init_cs();
usb_task();
}
|
3. To verify that the PIC24FJ128GC006 hardware works properly, I programmed the microcontroller with microchip XC16 compiler minimal code, based on the evaluation board example... and the hardware (the USB communication) works correctly (See the screenshot 3).
Code: |
#include <xc.h>
#include "main.h"
_CONFIG4(DSWDTPS_DSWDTPS1F // 1:68719476736 (25.7 Days)
& DSWDTOSC_LPRC // DSWDT uses LPRC as reference clock
& DSBOREN_OFF // DSBOR Disabled
& DSWDTEN_OFF // DSWDT Disabled
& DSSWEN_OFF // Deep Sleep operation is always disabled
& RTCBAT_OFF // RTC operation is continued through VBAT
& PLLDIV_NODIV // Oscillator divided by 2 (8 MHz input)
& IOL1WAY_OFF) // The IOLOCK bit can be set and cleared using the unlock sequence
_CONFIG3(WPFP_WPFP0 // Page 0 (0x00)
& SOSCSEL_ON // SOSC circuit selected
& WDTWIN_PS25_0 // Watch Dog Timer Window Width is 25 percent
& BOREN_OFF // Brown-out Reset Disabled
& WPDIS_WPDIS // Disabled
& WPCFG_WPCFGDIS // Disabled
& WPEND_WPSTARTMEM) // Write Protect from page 0 to WPFP
_CONFIG2(
POSCMD_NONE // GC006
& WDTCLK_LPRC // WDT uses SOSC input
& FCKSM_CSDCMD // Clock switching and Fail-Safe Clock Monitor are disabled
& FNOSC_FRCPLL // GC006 - Fast RC Oscillator with PLL module (FRCPLL)
& WDTCMX_LPRC // WDT always uses LPRC as its clock source
& IESO_OFF) // Disabled
_CONFIG1(WDTPS_PS32768 // 1:32,768 (not used)
& FWPSA_PR128 // 1:128
& WINDIS_OFF // Standard Watchdog Timer
& FWDTEN_WDT_DIS // WDT disabled in hardware; SWDTEN bit disabled
& ICS_PGx1 // GC006 - Emulator functions are shared with PGEC1/PGED1
& LPCFG_ON // Low voltage regulator controlled in sw by RETEN bit
& GWRP_OFF // Disabled
& GCP_OFF // Code protection is disabled
& JTAGEN_OFF) // Disabled
#define FOSC 32000000 /*Hz*/
void main() {
USBDeviceInit();
USBDeviceAttach();
while(1);
}
|
3. I studied the USB registers associated with each microcontroller and they are virtually identical except for two details:
a. The U1PWMCON register appears in the PIC24FJ128GC006 set of registers and it does not appear in the PIC24FJ256GB106 set. But this should not affect because the code generated by the CCS compiler does not call this register (ie it is not used) ..
b. In the U1CNFG2 register of the PIC24FJ128GC006 microcontroller there is a UVCMPSEL bit that does not appear in the U1CNFG2 register of the PIC24FJ256GB106 microcontroller. But this should not affect because the code generated by the XC16 compiler does not use this bit.
- - -
Now I can only compare the assemblers codes generated by both compilers... but it is not easy to do it because the way to resolve the issue is different and they follow different paths.
- - -
It should not be so complicated! Both microcontrollers (PIC24FJ128GC006 and PIC24FJ256GB106), on the USB working, should be identical! And, if PIC24FJ256GB106 works... ¿what happen with the PIC24FJ128GC006?...
- - -
Does anyone have any idea or suggestion for discover the mistery? |
|
|
|
|
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
|