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 will hang the PC usb port.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

usb will hang the PC usb port.
PostPosted: Sun Jul 30, 2006 5:30 pm     Reply with quote

info:
PC has a delphi interface to microchips mpusbapi.dll
Bulk transfer is used
the PIC is powered from the USB bus
It so far is working fine except for the following issue
issue:
The usb port hangs as a result of running the CCS debugger and either recompiling or stopping the process. Unplugging the PIC will also hang the usb port.
The USB connection sense pin is connected
The PC program USBview shows no usb device connected after the PIC hangs the port.
It is as if the USB port has a memory that the PIC was there and was enumerated but won't allow a second attempt after the PIC process is stopped and restarted or after a recompile.
If the PC is shut down and restarted or if the 18F4550 is plugged into another usb port it will work again ( but will hang that port also if the PIC process is interrupted)
Is there a PC utility to clear the usb ports to avoid a reboot?


Code:

#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
// 20 mhz external crystal is pre scalled by div 5 (PLL5) to 4mhz
// PLL multiplies by 16 to 96Mhz USBDIV post scales with div by 2 to 48MHZ
// CPU clock is post scaled with CPUDIV1 by with div by 2 to 48 MHZ
#use delay(clock=48000000)

#use rs232(debugger)

/////////////////////////////////////////////////////////////////////////////
//
// CCS Library dynamic defines.  For dynamic configuration of the CCS Library
// for your application several defines need to be made.  See the comments
// at usb.h for more information
//
/////////////////////////////////////////////////////////////////////////////
#define USB_HID_DEVICE     FALSE             //disable  HID
#define USB_EP1_TX_ENABLE  USB_ENABLE_BULK   //turn on EP1(EndPoint1) for IN bulk/interrupt transfers
#define USB_EP1_RX_ENABLE  USB_ENABLE_BULK   //turn on EP1(EndPoint1) for OUT bulk/interrupt transfers
#define USB_EP1_TX_SIZE    64                 //size to allocate for the tx endpoint 1 buffer
#define USB_EP1_RX_SIZE    64                 //size to allocate for the rx endpoint 1 buffer


/////////////////////////////////////////////////////////////////////////////
//
// If you are using a USB connection sense pin, define it here.  If you are
// not using connection sense, comment out this line.  Without connection
// sense you will not know if the device gets disconnected.
//       (connection sense should look like this:
//                             100k
//        5V    VBUS-----+----/\/\/\/\/\----- (I/O PIN ON PIC)
//                     |
//                     +----/\/\/\/\/\-----GND
//                             100k
//        (where VBUS is pin1 of the USB connector)
//
/////////////////////////////////////////////////////////////////////////////
#define USB_CON_SENSE_PIN PIN_B5 

/////////////////////////////////////////////////////////////////////////////
//
// Include the CCS USB Libraries.  See the comments at the top of these
// files for more information
//
/////////////////////////////////////////////////////////////////////////////
#include <pic18_usb.h>     //Microchip PIC18Fxx5x Hardware layer for CCS's PIC USB driver
#include <PicUSB.h>         //descriptors
#include <usb.c>           //handles usb setup tokens and get descriptor reports



#define PWR    PIN_B0
#define red_led PIN_B1
#define green_led PIN_B2
#define LED_ON  output_high
#define LED_OFF output_low

#define mode      received[0]
#define param1    received[1]
#define param2    received[2]
#define result    sent[0]
#define ack_connection 0x25
#define ack_led_cmd    0x55
#define id_string_size 65
char id_string[id_string_size]; /// global environment string version file date  time device clock
int8 index;
void usb_print(char c)
{

/// called from printf char by char
if (index <id_string_size) id_string[index++]=c;

}
void main(void) {

   int8 received[3];
   int8 sent[1];

   LED_OFF(PWR);
   printf("start\n\r");




   usb_init();                      //initialize USB

   usb_task();                      //enable usb interrupts
   usb_wait_for_enumeration();


   LED_ON(PWR);

   while (TRUE)
   {
      if(usb_enumerated())
      {
         if (usb_kbhit(1))
         {
            LED_OFF(PWR); // flash to indicate data received
            usb_get_packet(1, received, 3); //3bytes from pipe EP1 usb_get_packet(end pt, payload, payload size)

            if (mode == 0)
            {
               sent[0]=ack_connection;
               usb_put_packet(1, sent, 1, USB_DTS_TOGGLE); //send 1byte via EP1 to PC 0x25 to acknowledge
                                                           //usb_get_packet(end pt, payload, payload size)
               printf("mode=%LX param1=%LX param2=%LX \n\r",mode,param1,param2);
               /// now we send the pIC compile time info
               index=0; /// begining of string id_string
               printf(usb_print,"ver %s  %s  %s  %s",getenv("VERSION_STRING"),__DATE__,__TIME__,getenv("DEVICE"));
               // usb_print has written to id_string and index contains the length
               // return the string length and expect next call for data

               usb_put_packet(1, id_string, index, USB_DTS_TOGGLE);
               index=0;
               printf(usb_print,"%s",__FILE__);

               // usb_print has written to id_string and index contains the length
               // return the string length and expect next call for data

               usb_put_packet(1, id_string, index, USB_DTS_TOGGLE); // length is sent

            }

            if (mode == 1)
            {

               if (param1 == 1 ) LED_ON(red_led);
               if (param1 == 0 ) LED_OFF(red_led);
               if (param2 == 1 ) LED_ON(green_led);
               if (param2 == 0 ) LED_OFF(green_led);
               sent[0]=ack_led_cmd;
               usb_put_packet(1, sent, 1, USB_DTS_TOGGLE); //send 1byte via EP1 to PC 0x55 to acknowledge
               printf("mode=%LX param1=%LX param2=%LX\n\r",mode,param1,param2);
            }

           LED_ON(PWR);
         }// kbhit
      }// enum
   }// true
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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