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 message corruption

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







USB message corruption
PostPosted: Wed Jun 10, 2009 11:11 am     Reply with quote

I have a PIC18F65J50 setup as a USB bulk device. I have a computer program that sends it an information request, then the PIC returns info based on what was requested. The one particular command requests a 67byte string from the PIC. This seems to work smoothly.

The problem occurs when the PIC is busy doing something else and cannot send the string back. I want to know that the PIC got the request but is busy so I have the PIC respond with a 1-byte “busy” indicator instead of the 67bytes requested. After this happens I get strange results.

I’m using the demo version of USBTrace by SysNucleus to sniff the USB datastream. When everything is working correctly the PC sends 0x20 and the PIC responds with a TransferBufferLength of 0x43 and USBD Status of “USBD_STATUS_SUCCESS”. After the problem occurs when the PC sends 0x20, the PIC first responds with a TransferBufferLength of 0x40 and USBD Status of “USBD_STATUS_BABBLE_DETECTED” and if I send a 0x20 again the PIC responds with a TransferBufferLength of 0x3 and USBD Status of “USBD_STATUS_SUCCESS. Subsequent sends of 0x20 alternate between those two.

My USB_EP1_TX_SIZE = 64.

So it appears that when I issue “usb_puts(1,txdata,67,5);” after the busy command the computer thinks it should be receiving (1) 64byte packet instead of (1) 67byte message.

It’s interesting if I change USB_EP1_TX_SIZE from 64 to 32, when the BABBLE_DETECTED occurs the TransferBufferLength is still 0x40, not 0x20.

Are USB communications buffered by the computer and getting backed up? Is there a way to clear this buffer? I tried the following which didn't seem to help:
Code:
while(usb_kbhit(1)) usb_get_packet(1,rxdata,10);



In the PC software (I'm using mpusbapi.h from microchip) each time the function is called to get the data - the data pipes are opened then after the data is received the pipes are closed. This doesn’t seem to clear the problem. If I unplug/replug the USB cable everything runs smoothly again until the "busy" byte is returned.

Is there a different way that I should be letting the PC know that the PIC is busy and cannot send the requested data?

PCH Ver = 4.093

Thanks for your help
daveh
Guest







PostPosted: Wed Jun 17, 2009 11:18 am     Reply with quote

When the PIC sends a message via 'usb_puts' does it indicate to the computer the length of the message? If the PIC sends a 67byte message but the computer thinks the message is only to be 64bytes long would that indicate the PIC firmware is incorrectly calculating the message length?
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