This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

USB code for multiple data byte handling

Other Parts Discussed in Thread: MSP430F5529

Hi,

I found the some problem when i am trying to send different data packet using serial monitor tool for my USB CDC application( C3 example code)

My application is waiting for the receive flag and read only 31 bytes. if i send 31 bytes packet on each transmit it works fine, If i am sending random bytes its not working. I found that on 31 bytes receive it executes the code further.

Any way how to make application to read multiple data transmitssion from PC application?

Please suggest.

Nitesh 

  • Did you make any changes to the C3 example?
  • Sorry i forgot to mention i am using TI RTOS example "usbserialdevice_MSP_EXP430F5529LP_TI_MSP430F5529".
    where it reads 31 byte at a time. First time if i send lessor than 31 bytes packet it works ,if i am sending lesser byte for second time i am not able to handle my commands.

    what could be the issue. I found while debug on first receive it stored some n bytes in buffer on second packet transmission it stores in n+1th location, its not storing from 0th location. How to handle this in USB stack? can we reset the buffer ?

    With this if am calling USBCDCD_receiveData() API its not returning until 31 bytes are received.

    Please guide me
    Thanks in advance
    Nitesh
  • Hi Nitesh,

    The USBCDCD_receiveData() api is setup so that is needs to know the size of the data it is expecting.  You cannot send it random data when you set the size to be 31.  If you want to send random packet size than your application needs to tell the API what size to expect. 

    An example of this can be found in USB example, C4_PacketProtocol. This example can be downloaded via the Resource Explorer->MSPWare->Libraries->USB Developers Package->Example Projects -> CDC(Virtual COM Port) -> PacketProtocol.  You can adapt this to work with the TIRTOS example.

    Regards,

    Arthi 

     

  • You can't just query the USB API to find out how many bytes are available and then make the call to retrieve that many bytes? This is how the CDC C3 example works (at least in 4.20 dev kit). I used that as a basis for a variable-length ASCII control protocol and it works without problem.
  • Can i can first call the API to get the datasize available and then call again with datasize i receive in previous call?

    Ex.

    call API to read 5 bytes since my 5th byte is datasize available. i.e.  USBCDCD_receiveData (5)

    then call the API with datasize. i.e. USBCDCD_receiveData (datasize)

    Nitesh

  • Hi Nitesh,

    You can make a call to USBCDC_getBytesInUSBBuffer() to get the number of bytes in the buffer and then pass the result to USBCDCD_receiveData().

    If you want to know all the APIs that are available to you, the USBLib-ApiGuide.html is a great place to start.  This document is part of the USB Developers Package.

    Regards,

    Arthi

  • Hi Arthi,

    Thanks for the reply and suggestions.

    Nitesh

**Attention** This is a public forum