Hot!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

6 Replies Related Threads

    DarioG
    leaving this planet
    • Total Posts : 53071
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: porcodioland
    • 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
    --
    how does it feel, never having been loved? as life fades away, day after day, on this planet made of s h i t...

    #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
    leaving this planet
    • Total Posts : 53071
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: porcodioland
    • 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
    --
    how does it feel, never having been loved? as life fades away, day after day, on this planet made of s h i t...

    #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
    leaving this planet
    • Total Posts : 53071
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: porcodioland
    • 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
    --
    how does it feel, never having been loved? as life fades away, day after day, on this planet made of s h i t...

    #6
    ALMNET
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2017/07/26 12:33:14
    • Location: 0
    • Status: offline
    Re: RE: getsUSBUSART 2017/07/26 14:13:49 (permalink)
    0
    medidort
    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.


    Sorry for necroposting but i found this useful.

    To do a mirror usb communication, this is the code. I was using a PIC24, MPLABX 3.64, MCC 3.36 and usbFrameworkLite 1.25.2 for MCC.

    This function will send to pc what you get from pc. You can use any serial monitor to test it.


    void USBCDC_Comm_Test(){
         uint8_t size_rx;
         if(USBUSARTIsTxTrfReady()){
              size_rx = getsUSBUSART(gen_put_buffer, 64);
              putUSBUSART(gen_put_buffer, size_rx);
         }
    }

    Remember to update the Tx machine state every time you need to transfer data (Using CDCTxService)
    post edited by ALMNET - 2017/07/26 14:56:48
    #7
    Jump to:
    © 2017 APG vNext Commercial Version 4.5