About the usb port in my PIC

Discussion in 'Embedded Systems and Microcontrollers' started by ahgan84, Nov 21, 2013.

  1. ahgan84

    Thread Starter Member

    Dec 19, 2011
    Currently using the PIC18F25k50 and I want to send data through it's usb port. I'm using the below coding to do usb transmitting:

    Code ( (Unknown Language)):
    1.  if(!HIDTxHandleBusy(USBInHandle))    
    2.  {    
    3.        USBInHandle = HIDTxPacket(HID_EP,(BYTE*)&ToSendDataBuffer[0],64);    
    4.  }
    Is it that my data will straightaway transmit out after it reach the 'HIDTxPacket' function? Or it waits awhile and only send out in the background? How do we know that our protocol got successfully sent out?

    I'm sending four protocols out at one time. Protocol A (11 bytes data + 53 bytes 0x00), Protocol B (15 bytes data + 49 bytes 0x00), Protocol C (30 bytes data + 34 bytes 0x00) and Protocol D (11 bytes data + 53 bytes 0x00).

    I'm asking this because sometimes my receiver device miss out some data that I transmit out and usually it misses out protocol C which is the one with longest data. So, I don't know it is my usb transmitter problem or it's my receiver problem? Since I don't have the coding for my receiver, I only can check my transmitting part.
  2. ahgan84

    Thread Starter Member

    Dec 19, 2011
    I have solved this problem and apparently I overwrite the usb buffer before I transmit out. That's why the receiver will miss.

    Now I got another problem.
    I test until some point where the HIDTxHandleBusy(USBHandle) is always set, means the usb always busy and my usb can't transmit anymore. Do you know what cause this? How do I clear it so that I can transmit again?
  3. nigelwright7557

    Senior Member

    May 10, 2008
    If you want an already working project go to www.waitingforfriday.com.
    They have a PIC18F4550 project that includes the PIC and PC code.

    I have done a few projects with that as the basis and it works a treat.