USB CDC Communications for Dummies!


Closed Thread
Results 1 to 40 of 105

Hybrid View

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

  2. #2
    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.

  3. #3
    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 01:52.
    http://www.scalerobotics.com

  4. #4
    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 15:08. Reason: Found some files
    Louie

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

    Default Looks promising

    Okay, just copied the 18F2455.bas ver. 2.60 from the PBP folder over to the USB18 folder to replace the ver. 2.46 and it compiled 100%!
    Fingers are twitching, but need to wait until the coast is clear here before I can test it.

    Thank you for the help.
    Louie

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

    Default

    You can have more than one version of PBP installed.
    I have directories
    C:\PBP_247
    C:\PBP_250
    C:\PBP_260

    Then "point" to the version I want from MCS or FineLine or what ever I am using to invoke the compiler.

    So you may want to try a fresh install...
    Dave
    Always wear safety glasses while programming.

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

    Default Got the "ding ding"!

    Have heard it so many times before but never from this... what a giddy difference!
    To summarize this endeavor:
    Make sure 18F2455.bas revision is latest 2.60, found in PBP folder not the file in USB18 folder.
    Never assume a copy/pasted Config list is correct! Print out the .inc file for the chip found under MPASM Suite and go through each setting. That's how I found out why there was 0V on VUSB! Turn ON the VREG!
    Code:
    @   __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_ON_2L & _BOR_SOFT_2L & _BORV_2_2L & _VREGEN_ON_2L 
    @   __CONFIG    _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
    @   __CONFIG    _CONFIG3H, _CCP2MX_OFF_3H & _PBADEN_OFF_3H & _LPT1OSC_OFF_3H & _MCLRE_OFF_3H
    @   __CONFIG    _CONFIG4L, _STVREN_OFF_4L & _LVP_OFF_4L & _XINST_OFF_4L
    I think I've the USB bug now. Thanks for the infection!
    Louie

  8. #8
    Join Date
    Dec 2006
    Posts
    32

    Default Re: USB CDC Communications for Dummies!

    Hi Guys,

    Malc_c and myself are tinkering with a little project and while he's attacking the hardware side, im looking at the communication side of things and could do with a bit of info for this:

    the software on the PC (Not written by us, but freely available for people to use) uses the serial port to communicate to the external circuitry and the way it toggles things is by using the RTS and DTR pins setting them either high or low.

    Now my question is we want to setup a PIC18F via USB to be the toggle so thought the CDC comms would be an ideal springboard and I was wondering if when the pic is setup cia CDC comms can the USB detect the RTS/DTR signals? as the programs on the PC dont actually send 'data' but just use those 2 pins to toggle pins on an external device.

    Reason we want to use USB is for new machines (ie laptops/netbooks etc) that dont have parallel or serial ports, but still be able to utilise the software as there are quite a few differrent programs that all do the same thing (basically trying to bring the 21st century to the masses LOL!!!! )

    Many thanks in advance,

    Mark.

  9. #9
    Join Date
    Apr 2013
    Posts
    2

    Default Re: USB CDC Communications for Dummies!

    Hi guys,
    can you help me with program USB CDC Communicator on uC PIC18F47J53?
    I never use USB, this is my first try.
    I tried use the sample code from USB18 (CDC_demo). I tried rewrite the code but without success.
    Thx.

  10. #10
    Join Date
    Apr 2013
    Posts
    2

    Default Re: USB CDC Communications for Dummies!

    Proglem solved:

    Must use #congif for PIC.

    ' USB sample program for PIC18F47J53 CDC serial port emulation
    ' Requires PBP 2.60 or later

    Include "cdc_desc.bas" ' Include the HID descriptors

    Define OSC 48

    #CONFIG
    CONFIG WDTEN = OFF ;WDT disabled (enabled by SWDTEN bit)
    CONFIG PLLDIV = 3 ;Divide by 3 (12 MHz oscillator input)
    CONFIG STVREN = ON ;stack overflow/underflow reset enabled
    CONFIG XINST = OFF ;Extended instruction set disabled
    CONFIG CPUDIV = OSC1 ;No CPU system clock divide
    CONFIG CP0 = OFF ;Program memory is not code-protected
    CONFIG OSC = HSPLL ;HS oscillator, PLL enabled, HSPLL used by USB
    CONFIG FCMEN = OFF ;Fail-Safe Clock Monitor disabled
    CONFIG IESO = OFF ;Two-Speed Start-up disabled
    CONFIG WDTPS = 32768 ;1:32768
    CONFIG DSWDTOSC = INTOSCREF ;DSWDT uses INTOSC/INTRC as clock
    CONFIG RTCOSC = T1OSCREF ;RTCC uses T1OSC/T1CKI as clock
    CONFIG DSBOREN = OFF ;Zero-Power BOR disabled in Deep Sleep
    CONFIG DSWDTEN = OFF ;Disabled
    CONFIG DSWDTPS = 8192 ;1:8,192 (8.5 seconds)
    CONFIG IOL1WAY = OFF ;IOLOCK bit can be set and cleared
    CONFIG MSSP7B_EN = MSK7 ;7 Bit address masking
    CONFIG WPFP = PAGE_1 ;Write Protect Program Flash Page 0
    CONFIG WPEND = PAGE_0 ;Start protection at page 0
    CONFIG WPCFG = OFF ;Write/Erase last page protect Disabled
    CONFIG WPDIS = OFF ;WPFP[5:0], WPEND, and WPCFG bits ignored
    #ENDCONFIG


    buffer Var Byte[16]
    cnt Var Byte


    OSCTUNE.6 = 1 ' Enable PLL for 18F47J50 family
    Pause 10

    USBInit ' Get USB going

    '************************************************* ***************
    '* Set PORTA, PORTB, PORTC, PORTD PORTE to input/output *
    '************************************************* ***************
    TRISA = %00100010 ' Set PORTA to output
    TRISB = %00001000 ' Set PORTB to output
    TRISC = %00---000 ' Set PORTC to output

    PortA = %00000000 ' Set PORTA to 0
    PortB = %00000000 ' Set PORTB to 0
    PortC = %00000000 ' Set PORTC to 0
    PortD = %00000000 ' Set PORTD to 0
    PortE = %00000000 ' Set PORTE to 0


    '************************************************* ***************
    '* SET LCD *
    '************************************************* ***************
    ' Define LCD registers and bits
    Define LCD_DREG PORTD
    Define LCD_DBIT 4
    Define LCD_RSREG PORTB
    Define LCD_RSBIT 0
    Define LCD_EREG PORTB
    Define LCD_EBIT 1
    DEFINE LCD_LINES 2
    DEFINE LCD_COMMANDUS 1500
    DEFINE LCD_DATAUS 50

    Pause 1000 ' Wait for LCD to start up

    '************************************************* ***************
    '* LOOP *
    '************************************************* ***************
    ' 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] = "O"
    buffer[1] = "K"
    buffer[2] = 13
    buffer[3] = 10
    buffer[4] = 0

    outloop:
    USBService ' Must service USB regularly
    USBOut 3, buffer, 5, outloop

    Goto idleloop ' Wait for next buffer

  11. #11
    Join Date
    Jun 2011
    Location
    Philippines
    Posts
    223

    Default Re: USB CDC Communications for Dummies!

    Hi.. I have windows 7 64bit machine... I download the 64_mchpcdc.inf provided by mackrackit...and copy and paste it in the Windows\sysWOW64 folder, I also reboot the machine but I'm getting exclamation icon(CDC - R232 Emulation Demo) in the devices and printers window. What do you think I'm doing bad? Please give advice.

    Thanks in advance,
    tacbanon

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

    Default Re: USB CDC Communications for Dummies!

    The driver provided with PBP now has 64 bit support added. So you do not need the one I linked to, although it should still work.
    I think your problem might be that you copied it to a directory rather than letting the OS install it. Try deleting the file from the sysWOW directory, then do a reboot.
    When your project is plugged into your PC windows should bring up the usual dialog asking to install a driver. Do not let windows look for it, point to where the file has been saved to and let windows do the installing. You then should see a virtual com-port in device manager.
    Dave
    Always wear safety glasses while programming.

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