Pic18F2455 and USB .. Need some lights to find my bug

Discussion in 'Embedded Systems and Microcontrollers' started by ackn, Jan 3, 2012.

  1. ackn

    Thread Starter New Member

    Jan 3, 2012

    I have developped an application on PIC18F2455 that sends quotation on usb.
    the application itself is running pretty well, except that I have a problem on the USB stack that happens quite a lot.
    The stack Hangs on the PIC.

    What the application does :
    The pic received from the PC through USB commands like Init, start, stop
    whn the Pic is in start mode, it reads an digital encoder and a push button, the encoder modifies the value displayed but the 7-Seg led display, wile sending to the PC the value. and the button validate the value, and put itself in a stop state

    every time the problem appears, is after the validation, when the PC sent a start or anything else, the PIC doesn't receive it.
    on more 200 "hung" only once the problem occurs when changing the value, meaning that the PC didn't receive new values and validation, and the pic couldn't receive the init command.

    As the code has a WatchDog (I have tested it) I came to the fact tat the application is still running properly, but the usb stack, tells him there is no data.

    The application is in polling mode, this is the only thing I remember I have change on the default setting I have found in the usb_config.h

    As I cannot force the application to hang, I cannot debug it...
    Can you enlighten me what could cause the usb stack to freeze and where to look ?

    thank you

  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    Does your main loop look something like this:

    Code ( (Unknown Language)):
    2.     while(1)
    3.     {
    4.         #if defined(USB_POLLING)
    5.         // Check bus status and service USB interrupts.
    6.         USBDeviceTasks(); // Interrupt or polling method.  If using polling, must call
    7.                           // this function periodically.  This function will take care
    8.                           // of processing and responding to SETUP transactions
    9.                           // (such as during the enumeration process when you first
    10.                           // plug in).  USB hosts require that USB devices should accept
    11.                           // and process SETUP packets in a timely fashion.  Therefore,
    12.                           // when using polling, this function should be called
    13.                           // regularly (such as once every 1.8ms or faster** [see
    14.                           // inline code comments in usb_device.c for explanation when
    15.                           // "or faster" applies])  In most cases, the USBDeviceTasks()
    16.                           // function does not take very long to execute (ex: <100
    17.                           // instruction cycles) before it returns.
    18.         #endif
    21.         // Application-specific tasks.
    22.         // Application related code may be added here, or in the ProcessIO() function.
    23.         ProcessIO();        
    24.     }//end while