getsUSBUSART

Author
Alex.Affonso
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2007/06/05 21:12:46
  • Location: 0
  • Status: offline
2007/07/03 20:32:11 (permalink)
0

getsUSBUSART

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,
#1

5 Replies Related Threads

    DarioG
    Scheisse Menschen
    • Total Posts : 52256
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: hi there
    • Status: offline
    RE: getsUSBUSART 2007/07/04 00:19:36 (permalink)
    0
    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.

    Dario Greggio
    --
    Wouldn't it be wonderful, if you lost one son for every promise you don't keep?
    #2
    medidort
    Starting Member
    • Total Posts : 46
    • Reward points : 0
    • Joined: 2011/11/26 07:41:31
    • Location: 0
    • Status: offline
    Re: RE: getsUSBUSART 2012/02/18 07:36:30 (permalink)
    0
    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
    #3
    DarioG
    Scheisse Menschen
    • Total Posts : 52256
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: hi there
    • Status: offline
    Re: RE: getsUSBUSART 2012/02/18 07:45:40 (permalink)
    0
    If your USB device is enumerated and stable, then it's not a hardware issue

    Dario Greggio
    --
    Wouldn't it be wonderful, if you lost one son for every promise you don't keep?
    #4
    medidort
    Starting Member
    • Total Posts : 46
    • Reward points : 0
    • Joined: 2011/11/26 07:41:31
    • Location: 0
    • Status: offline
    Re: RE: getsUSBUSART 2012/02/18 16:15:12 (permalink)
    0
    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; } } } } }
    #5
    DarioG
    Scheisse Menschen
    • Total Posts : 52256
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: hi there
    • Status: offline
    Re: RE: getsUSBUSART 2012/02/18 17:33:30 (permalink)
    0
    Can you please post your code using another browser, say Firefox <= 5.x ?

    thanx

    Dario Greggio
    --
    Wouldn't it be wonderful, if you lost one son for every promise you don't keep?
    #6
    Jump to:
    © 2017 APG vNext Commercial Version 4.5