USB CDC Communications for Dummies!


Closed Thread
Results 1 to 40 of 105

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Posts
    6

    Default

    arniepj, I cannot get your code working either.

    There are no config fuses set in the code, and I do not know what they are supposed to be for this application.

    I cannot fing any hints in your code as to how to get it to work.

    Any help is much appreciated.

  2. #2
    Join Date
    Dec 2008
    Posts
    48

    Default 18F2550 w/ 4MHz

    Thanks alot. I popped a 4MHz clock (in place of 12 MHz) and compiled successfully. However, with the same result: the program compiles and the chip is programmed fine. I plug the USB cable into the test PC (and others) and windows will prompt as an unrecognized device. I go into the driver configuration and when I load the .inf file, windows again prompts that there is no hardware information available.

    Have gone through the data sheet and fuses very close ... but the same result, which has me wondering about the cdc drivers that I am using for the PC....

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    If it compiles ... The number one cause of USB failure, is improper Oscillator Configurations.

    For 4Mhz Crystal ...
    Code:
    @   __CONFIG   _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    @   __CONFIG   _CONFIG1H, _FOSC_HSPLL_HS_1H
    For 8Mhz Crystal ...
    Code:
    @   __CONFIG   _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    @   __CONFIG   _CONFIG1H, _FOSC_HSPLL_HS_1H
    For 20Mhz Crystal ...
    Code:
    @   __CONFIG   _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    @   __CONFIG   _CONFIG1H, _FOSC_HSPLL_HS_1H
    For any of the above configurations, use ...
    Code:
    DEFINE OSC 48
    Number two reason ... improper capacitance on VUSB pin. (0.22uF or higher)

    #3, connecting +5V from USB port to +5V supply from powered project. (very bad)
    Ok, that's not really #3, but it is bad.

    Last edited by Darrel Taylor; - 1st January 2009 at 03:47. Reason: OSC 48
    DT

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

    Default USB CDC_DEMO with DT_INTS

    Here is some PBP 2.60 code (cut and pasted) from Darrel, with the "Hello World" example added in. Darrel's main code is taken from another thread, located here: http://www.picbasic.co.uk/forum/show...4292#post94292 . It uses DT_INTS ( instant interrupts ) to service the USB. As always, DT_INTS can then also be used for all types of other things, while the USB connection is kept alive.

    Name:  schematic-large.gif
Views: 14255
Size:  28.8 KB

    Code:
    '  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.
    
    '  Config files for PIC18F4550 with 20 mhz crystal
    
    asm
            __CONFIG    _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
            __CONFIG    _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
            __CONFIG    _CONFIG2L, _PWRT_OFF_2L & _BOR_ON_2L & _BORV_3_2L & _VREGEN_ON_2L
            __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
            __CONFIG    _CONFIG3H, _CCP2MX_ON_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_ON_3H
            __CONFIG    _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L
    endasm
    DEFINE OSC 48
    
    INCLUDE "cdc_desc.bas" 'Descriptor file    for CDC    serial demo
    
    ;--- Setup Interrupts ------------------------------------------------------
    INCLUDE "DT_INTS-18.bas"     ; Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"  ; Include if using PBP interrupts
    buffer    Var    Byte[16]
    cnt    Var    Byte
    ASM
    INT_LIST  macro     ; IntSource,          Label,  Type, ResetFlag?
            INT_Handler     USB_INT,  _DoUSBSERVICE,   ASM,  yes
            INT_Handler     INT_INT,    _Handle_INT,   PBP,  yes
        endm
        INT_CREATE             ; Creates the Low Priority interrupt processor
    
        ;INT_ENABLE  USB_INT   ;we will do this after we initialize USB
        INT_ENABLE  INT_INT
    ENDASM
    
    
    ;----[Initialise USB and Interrupts]----------------------------------------
        PAUSE 100                    ; Allow VUSB to stabilize
        USBINIT                      ; initialize the USB driver
        USBSERVICE                   ; service it once
        UIE = $7F                    ; enable USB interrupts
        UEIE = $9F                   ; enable USB Error interrupts
    @   INT_ENABLE  USB_INT
    
    ;----[Main program loop]----------------------------------------------------
    Main:
        cnt = 16        ' Specify input buffer size
        USBIn 3, buffer, cnt, main
    
    ' 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:
        USBOut 3, buffer, 14, outloop
    
    GOTO Main
    
    ;----[Interrupt handler -- Service USB]-------------------------------------
    DoUSBSERVICE:
          USBSERVICE                   ; Run the SERVICE routines
    @ INT_RETURN
    
    ;----[Interrupt handler -- INT]
    Handle_INT:
     ; something here
    @ INT_RETURN
    Last edited by ScaleRobotics; - 31st December 2010 at 20:51.
    http://www.scalerobotics.com

  5. #5
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219

    Default Doesn't want to play!

    Using PBP 2.60A and MPASM for my 1st attempt with USB on a PIC18F2455, I followed these directions:
    Copy the PBP\USB18 folder to a new location.
    You do not want any files left over from previous versions of PBP, so don't try to copy it into an existing project folder.
    Open and compile cdc_demo.bas with the proper chip selected.
    Program the chip and test. Done deal.
    Copied complete USB18 folder to Documents\MCS to work with.

    Wouldn't even start to compile
    1st error: Variable USBReserveMemory position request 1024 beyond RAM_END 1023
    Did: Opened up PIC18F2455.BAS and enabled BANK4

    Started compiling! only to end in errors...
    2nd error: ERROR 180.....mcs\usb18\usb18mem.asm 116: RES directive cannot reserve odd number of bytes in PIC18 absolute mode
    ERROR 231....usb18mem.asm 116: no memory has been reserved by this instruction
    This was repeated for many lines.
    Did: Looked at usb18mem.asm line 116 and 117 and on and could only stare.
    Code:
    ; (See usbctrltrf.c)
    ctrl_trf_state	res	1		; Control Transfer State
    ctrl_trf_session_owner res 1		; Current transfer session owner 
    wCount		res	2		; Data counter
    Now what?
    Reading through the forum for this problem and it seems I'm the only one? Can't be that special. Can someone please help a dude out?
    Louie

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

    Default

    The USB files need to be in the same directory as your project and it works best if each project has a directory of its own.

    Does this example help any?
    http://www.picbasic.co.uk/forum/cont...USB-SD-LOGGING
    Dave
    Always wear safety glasses while programming.

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

    Default

    Quote Originally Posted by LinkMTech View Post
    Wouldn't even start to compile
    1st error: Variable USBReserveMemory position request 1024 beyond RAM_END 1023
    Did: Opened up PIC18F2455.BAS and enabled BANK4
    Are you sure you are working with 2.60 files?

    The BAS file should look like this to start with (no modifications required):

    Code:
    '****************************************************************
    '*  18F2455.BAS                                                 *
    '*                                                              *
    '*  By        : Leonard Zerman, Jeff Schmoyer                   *
    '*  Notice    : Copyright (c) 2008 microEngineering Labs, Inc.  *
    '*              All Rights Reserved                             *
    '*  Date      : 09/12/08                                        *
    '*  Version   : 2.60                                            *
    '*  Notes     :                                                 *
    '****************************************************************
    
    BANKA   $0000, $005F
    BANK0   $0060, $00FF
    BANK1   $0100, $01FF
    BANK2   $0200, $02FF
    BANK3   $0300, $03FF
    BANK4   $0400, $04FF
    BANK5   $0500, $05FF
    BANK6   $0600, $06FF
    BANK7   $0700, $07FF
    'EEPROM  $F00000, $F000FF
    LIBRARY "PBPPIC18"
    
            include "PIC18EXT.BAS"
    
    PORTL   VAR     PORTB
    PORTH   VAR     PORTC
    TRISL   VAR     TRISB
    TRISH   VAR     TRISC
    
            include "PBPPIC18.RAM"
    USBMEMORYADDRESS Con    $400    ' USB RAM starts here
    
    '*-----------------------* EOF 18F2455.BAS *--------------------*
    Last edited by ScaleRobotics; - 10th January 2011 at 02:52.
    http://www.scalerobotics.com

  8. #8
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219

    Default

    Thanks Dave, I'm gonna study the project for more insight.

    Are you sure you are working with 2.60 files?
    Just checked the files I have and nope! It's version 2.46!
    When I upgraded to 2.60 recently I also downloaded the patch that included the missing PIC18's. Where did I miss getting the latest 2.60 files?

    Okay just did some more digging and found the latest 18F2455.bas in the PBP folder not in the USB18 folder. Will keep looking for the rest.
    Last edited by LinkMTech; - 10th January 2011 at 16:08. Reason: Found some files
    Louie

  9. #9
    Join Date
    Dec 2008
    Posts
    48

    Default

    This might sound like a crazy question but....

    Do I have to install a bootloader of some kind on the 18F2550? If so, where do I get hold of one compatible with the project(s) this thread is about?

    This is a great thread. When I get it all going, will package and contribute accordingly.

    --Kirt

  10. #10
    Join Date
    Dec 2008
    Posts
    48

    Default

    Thank you Darrel. Here are the configs from the code arnie posted earlier, which is very similar to the configs (except I used a 12 MHz oscillator) that I created earlier according to the data sheet and include file review.

    asm
    CONFIG_REQ
    CONFIG1L = _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    ; ; ; USB clock source comes from the 96 MHz PLL divided by 2
    ; ; [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2] Determines cpu speed
    ; No prescale (4 MHz oscillator input drives PLL directly)
    CONFIG1H = _FOSC_XTPLL_XT_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
    ; ; ; Oscillator Switchover mode disabled
    ; ; Fail-Safe Clock Monitor disabled
    ; XT oscillator, PLL enabled, XT used by USB
    CONFIG2L = _PWRT_ON_2L & _BOR_ON_2L & _BORV_2_2L & _VREGEN_ON_2L
    CONFIG2H = _WDT_OFF_2H
    CONFIG3H = _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
    CONFIG4L = _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
    ; Removed ICPRT_OFF_4L used with 18F4550
    endasm


    Did not have the define statement included though.... try that and see soon.
    Also, noticed that your oscillator settings were HS instead of XT.

    --Kirt

  11. #11
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    If you're trying to use the new style CONFIG with PBP, you should be aware that it can't be placed in your program.
    It has to be the first thing loaded, which means it must be in a file that gets loaded before the PBP library. (Not fun)

    The original __CONFIG statements are still the way to set configs with PBP.
    In other words, please delete what you just posted from your program, and follow the suggested __CONFIG style.
    Also, noticed that your oscillator settings were HS instead of XT.
    HS mode will always drive a crystal that might qualify for XT mode. The reverse is not always true. I err on the Cautious side.
    DT

  12. #12
    Join Date
    Dec 2008
    Posts
    48

    Default

    Thank you Darrel.

    I was going through that the other day and the only way I could get code to compile is the way it is written now... but apparently not compiling correctly.

    When I use the __config statements, the following appears rather consistently.

    AUTO2550.ASM 72 : Overwriting previous address contents (0000)
    Error[118] C:\PROJECTS\KEYFER\AUTO2550\AUTO2550.ASM 72 : Overwriting previous address contents (0001)

    This doesn't require a CDC bootloader for the PIC, does it? Also noticed that the cdc windows drivers only have an .inf file and a .cat file, but no .sys file.

    --Kirt

  13. #13
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    There we go. That one must be #3

    What to do if i get "overwriting previous address content" error message? (mister_e)
    http://www.picbasic.co.uk/forum/show...75&postcount=5
    DT

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 : 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