USB CDC Communications for Dummies!


Closed Thread
Results 1 to 40 of 105

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default Re: USB CDC Communications for Dummies!

    The default config in the PBP directory looks correct for a 20MHz external.
    Can you confirm that the chip is running at 48MHz?
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869

    Default Re: USB CDC Communications for Dummies!

    I can't confirm it right now, but I feel it is. I have been playing with receiving serial at 115K without any problems. But I was using configs set in code. I also tried those same configs, still nothing. I will double check all configs tonight.

    Thank you for verifing the defaults should work. I know Darryl said not to mess with the code until it connected, but I think I can at least toggle a pin to make sure there is life, and at what speed.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default Re: USB CDC Communications for Dummies!

    Post your code. Maybe there is something else.
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869

    Default Re: USB CDC Communications for Dummies!

    Here it is:
    Code:
    ' USB sample program for PIC18F4550 CDC serial port emulation
    '  Requires PBP 2.60 or later
    '  Compilation of this program requires that specific support files be
    '  available in the source directory.  For detailed information, see
    '  the file PBP\USB18\USB.TXT.
     Include "cdc_desc.bas" ' Include the HID descriptors
    Define  OSC     48
    buffer Var Byte[16]
    cnt Var Byte
    
     OSCTUNE.6 = 1  ' Enable PLL for 18F87J50 family
     Pause 10
     USBInit   ' Get USB going
    ' Wait for USB input
    idleloop:
     USBService  ' Must service USB regularly
     cnt = 16  ' Specify input buffer size
     USBIn 3, buffer, cnt, idleloop
    ' Message received
     buffer[0] = "H"
     buffer[1] = "e"
     buffer[2] = "l"
     buffer[3] = "l"
     buffer[4] = "o"
     buffer[5] = " "
     buffer[6] = "W"
     buffer[7] = "o"
     buffer[8] = "r"
     buffer[9] = "l"
     buffer[10] = "d"
     buffer[11] = 13
     buffer[12] = 10
     buffer[13] = 0
    outloop:
     USBService  ' Must service USB regularly
     USBOut 3, buffer, 14, outloop
     Goto idleloop  ' Wait for next buffer
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  5. #5
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869

    Default Re: USB CDC Communications for Dummies!

    revisied code with a speed test added
    Code:
    ' USB sample program for PIC18F4550 CDC serial port emulation
    '  Requires PBP 2.60 or later
    '  Compilation of this program requires that specific support files be
    '  available in the source directory.  For detailed information, see
    '  the file PBP\USB18\USB.TXT.
     Include "cdc_desc.bas" ' Include the HID descriptors
    
    Define  OSC     48
    trise.3 = 0
    buffer Var Byte[16]
    cnt Var Byte
        
     OSCTUNE.6 = 1  ' Enable PLL for 18F87J50 family
     Pause 10
    '*****************************************
    '--------------Speed test 
     
    speedtest:
        toggle porte.3
        goto speedtest
     
    '--------------End test
    '******************************************    
        
        USBInit   ' Get USB going
    ' Wait for USB input
    idleloop:
        
     USBService  ' Must service USB regularly
     cnt = 16  ' Specify input buffer size
     USBIn 3, buffer, cnt, idleloop
    ' Message received
     buffer[0] = "H"
     buffer[1] = "e"
     buffer[2] = "l"
     buffer[3] = "l"
     buffer[4] = "o"
     buffer[5] = " "
     buffer[6] = "W"
     buffer[7] = "o"
     buffer[8] = "r"
     buffer[9] = "l"
     buffer[10] = "d"
     buffer[11] = 13
     buffer[12] = 10
     buffer[13] = 0
    outloop:
     USBService  ' Must service USB regularly
     USBOut 3, buffer, 14, outloop
     Goto idleloop  ' Wait for next buffer
    the results of the speed test: pin toggles at 3Mhz. To be clear, there is .3333uS between toggles. Now I don't feel like that is correct. lets see: 48Mhz=12Mips. So thats .08uS per instruction? So we are executing 4 instructions? Hmm, that doesn't sound right.

    Ok, I will see if someone else can think better then I this evening
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default Re: USB CDC Communications for Dummies!

    Might be a problem with the buffer size compared to the data being sent. They are different sizes.

    Here is an example:
    Code:
    Buffer    VAR BYTE[16]
    Cnt       VAR BYTE
    B0        VAR BYTE
    B1        VAR BYTE
    
    ADCON1 = 15               ' Set all I/Os to Digital      
    CMCON = 7                 ' Disable Comparators
    Cnt = 16 
      
    for b0 = 0 to 15
        lookup b0,["USB CONNECTED!",10,13],B1 
        BUFFER(B0) = B1
        NEXT B0
     USBINIT 
    ' Main Program Loop
    Loop:
        USBService        ' Must service USB regularly
        USBOut 3, Buffer, Cnt, loop
        goto loop
    As for your speed test... my brain is ready to fuss out for the day also...
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869

    Default Re: USB CDC Communications for Dummies!

    Hmmm.. I would think OS should still see it as a new device even if thats the case.

    Well I am studing the schematic now, I am not sure I have the "CAP" on Vusb. But I can say this thing works with a USB bootloader no problem. Now does that mean winblows will see it? IDK

    I see there are pullups on the data lines. And according to the datasheet, The internal pullups must be disabled. I have been looking at the include file, and I think there are being set.

    I am just about to give up on this "pre-configured" answer. After all, it may NOT be the answer for this chip anyway. I will start looking at your solution to see if I can make that work.
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

Similar Threads

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

Members who have read this thread : 3

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