getsUSBUSART

Post
Alex.Affonso
New Member
2007/07/03 20:32:11
Hello!
 
I am having some problems with the function getsUSBUSART from CDC firmware - Microchip. For example:
 
char input_buffer[64];
void example(void)
{
 if(Switch3IsPressed())
 {
    if(getsUSBUSART(input_buffer, 3))
    {
       if(mUSBUSARTIsTxTrfReady())
          mUSBUSARTTxRam((byte *) input_buffer, 3);
    }
 }
}
 
In the HyperTerminal I press: 123 (ASCII = 0x31, 0x32, 0x33)
 
When I press the switch 3:
 
- In the first time the PIC send to PC this sequence: 1(ñ
- In the second time the PIC send to PC this sequence: 2(ñ
- In the third time the PIC send to PC this sequence: 3(ñ
 
I was waiting for the sequence 123 (ASCII = 0x31, 0x32, 0x33) for the first time when I press the switch 3 and "no sequence" when I press it again.
 
Are the any error in the code below? How does getsUSBUSART function work?
 
Best Regards,
DarioG
Scheisse Menschen
RE: getsUSBUSART 2007/07/04 00:19:36
Hi, another guy had a similar problem, and it's due on a mis-interpretation of how getsUSBUSART() works.

It will return whatever chars have been received by USB at that moment. Since the loop inside of which getUSBUSART runs can be faster than the transmiting ratio from the PC, you do grab those chars one at a time.
I suspect (never used it yet) that getUSBUSART will return "the number of captured chars", which can be less than "3" (the max-size of given buffer).

This is consistent with what you see.
medidort
Starting Member
Re: RE: getsUSBUSART 2012/02/18 07:36:30
I am having the same problem. How can I solve it? I get garbage on the USB. Can I use a capacitor to filter? Thanks
DarioG
Scheisse Menschen
Re: RE: getsUSBUSART 2012/02/18 07:45:40
If your USB device is enumerated and stable, then it's not a hardware issue
medidort
Starting Member
Re: RE: getsUSBUSART 2012/02/18 16:15:12
I have solved the garbage problem. Now I have another problem. I am using the hyperterminal to send data. I press a key and the pc sends to pic and the pic sends it back. Now my problem is that when i press the first key it keeps sending that character until i press another key and then it keeps sending the new key until i press another one. How can i solve that? my code is : void main(void){ unsigned char dataReceived; unsigned char data; unsigned char *pData = &data; InitializeSystem(); while(1){ USBDeviceTasks(); if((USBGetDeviceState() \ 0){ if(USBUSARTIsTxTrfReady()){ mUSBUSARTTxRam(pData, 1); dataReceived = 0; } } } } }
DarioG
Scheisse Menschen
Re: RE: getsUSBUSART 2012/02/18 17:33:30
Can you please post your code using another browser, say Firefox <= 5.x ?

thanx