USB CDC Communications for Dummies!


Closed Thread
Results 1 to 40 of 105

Hybrid View

  1. #1
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    this section
    Code:
    COM_RX:
    hserin 1, exitsub, [bufferrx]
    serbufferrx[0]=bufferrx
    goSUB usb_TX
    goSUB main
    I guess you want a Return there.

    And when you deal with HSEROUT/HSERIN, you should use DEFINEs, unless, it will use default 2400 Bauds baudrate.

    AND you must add DEFINE OSC 48 at the top of your code as well.

    That should be enough to start
    Last edited by mister_e; - 15th February 2009 at 10:53.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  2. #2
    Join Date
    Nov 2008
    Posts
    12

    Default

    Hi Mister_e

    Thanks for the response. I did already have a DEFINE OSC 48 already near start of the code, i have changed it to be return instead of GoSub Main. Thanks. As for your quote below

    Quote Originally Posted by mister_e View Post
    this section
    you should use DEFINEs, unless, it will use default 2400 Bauds baudrate.
    Would you be able to provide a bit more detail as regards the DEFINEs you mention, i have no clue what you mean by that.

    Thanks
    Last edited by ricgar; - 15th February 2009 at 17:57.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    DEFINE for HSEROUT are explained in the PBP manual
    The serial parameters and baud rate are specified using DEFINEs:

    ' Set receive register to receiver enabled
    DEFINE HSER_RCSTA 90h

    ' Set transmit register to transmitter enabled
    DEFINE HSER_TXSTA 20h

    ' Set baud rate
    DEFINE HSER_BAUD 2400

    ' Set SPBRG directly (normally set by HSER_BAUD)
    DEFINE HSER_SPBRG 25

    HSEROUT assumes a 4MHz oscillator when calculating the baud rate. To maintain the proper baud rate timing with other oscillator values, be sure to DEFINE the OSC setting to the new oscillator value.
    In your case, the DEFINE list would look something like
    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_SPBRG 25  ' 115200 Baud @ 48MHz, 0.16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    HTH
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Jun 2009
    Posts
    8

    Unhappy when i have delay nothing is working...!!!! WHY

    DEFINE OSC 48

    Buffer VAR BYTE[16]
    Cnt VAR BYTE
    B0 VAR BYTE
    B1 VAR BYTE
    led var porta.3

    ADCON1 = 15 ' Set all I/Os to Digital
    CMCON = 7 ' Disable Comparators
    Cnt = 16

    USBInit ' Initialize USART
    start:
    for b0 = 0 to 15
    lookup b0,["USB CONNECTED!",10,13],B1
    BUFFER(B0) = B1
    NEXT B0
    gosub send
    ledl:
    high led
    pause 1000'(when i have delay nothing is working)
    low led

    afterled:
    for b0 = 0 to 15
    lookup b0,["closed led",10,13],B1
    BUFFER(B0) = B1
    NEXT B0
    gosub send
    goto start

    send:
    USBService ' Must service USB regularly
    USBOut 3, Buffer, Cnt,send
    return
    end

  5. #5
    Join Date
    Jun 2009
    Posts
    8

    Default

    everything is working perfect i have connect it with labview but when i am using PAUSE 1000 nothing is working !!!!!!!

  6. #6
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530

    Default

    Its the:

    Code:
    USBService ' Must service USB regularly
    part. It must be serviced every 10 ms, or your communication will drop. So your pause 1000 is about 100 times too long. Some people have used Darrel's interrupt routines for the service interval. Here is one link:

    http://www.picbasic.co.uk/forum/show...5302#post45302
    http://www.scalerobotics.com

  7. #7
    Join Date
    Jun 2009
    Posts
    8

    Default

    is theare any other way to make it working because i cannot to it working with this way....!!!!

Similar Threads

  1. Simple USB Comms Problem
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 6th January 2010, 20:17
  2. One USB keyboard to Two USB Ports
    By picnaut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th June 2009, 00:04
  3. USB CDC help..
    By jchandir in forum USB
    Replies: 6
    Last Post: - 22nd November 2008, 21:23
  4. Replies: 4
    Last Post: - 5th November 2008, 16:21
  5. USB PIC without USB Connection
    By Tissy in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 26th December 2005, 17:39

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts