USB CDC Communications for Dummies!


Closed Thread
Results 1 to 40 of 105

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Posts
    48

    Default

    Are you getting it to recognize the device when you initially plug into your computer?

    This is the most straightforward and easiest to run so far. It is based on SquibbCake's code in the first posting.

    Arnie >> What was your code supposed to do? When I thought I got it working (which it does for the most part), it was blowing a bunch of "B" and special characters across the screen. But upon closer review of your code, it looks like it is looking for user input, then sending data out on USART TX pins. Can you tell us how it is supposed to function and include a link to a similar schematic?
    Attached Files Attached Files

  2. #2
    Join Date
    Dec 2008
    Posts
    48

    Default

    I have gone throught the microchip document fairly thoroughly but have a few questions about some of the PicBasic Pro commands. In the USBIN and USBOUT functions, the first argument is endpoint. What is this referring to? How is that number determined?

  3. #3
    Join Date
    Aug 2005
    Posts
    57

    Default

    The code is a test program and actually works with a VB6 interface and yes it is looking for commands.The usart output was initially just to let me know the code was running.You can have serial data simultaneously on the pc's comport and the virtual comport(usb).From a terminal program send MX8 to start the usb xmit and MX9 to stop.If you want the VB code http://www.picbasic.co.uk/forum/show....php?t=7372.If you think the CDC demo was fun,Hid is even better.

  4. #4

    Default Redefinition of VAR.

    Can sombody please give me a hint what i am do-ing wrong i keep getting the following error
    C:\PBP246\PIC18EXT.BAS ERROR Line 12: Redefinition of VAR.
    Here is the code i use


    Code:
    INCLUDE "MODEDEFS.BAS"
    INCLUDE "18F4550.BAS"		; USB descriptors for CDC demo
    
    DEFINE OSC 20				' Define crystal as 20Mhz
    
    'Define ACDIN parameters
    Define ADC_BITS 10 			' Set number of bits in result
    DEFINE ADC_CLOCK 3 			' Set clock source ( 3 = RC )
    DEFINE ADC_SAMPLEUS 50 		' Set sampling time to micro-seconds
    
    'This Part set PORTA 0-3 an analog inputs,4 as digital 
    TRISA = %00011111 			'set PORTA 0-5 as inputs
    ADCON1 = %00001010 			'ADC use vss and vdd as ref.
    ADCON2 = %10000111			'FRC (clock derived from A/D RC oscillator),Right justify output
    
    
    TRISD = %00001111			'Set port d 0-3 as inputs and 4-7 as outputs
    TRISB = %10011000
    
    '**************************************Variables*********************************************
    buffer	Var	Byte[16]
    cnt	Var	Byte
    LED	Var	PORTD.4
    
    USBInit
    Low LED		' LED off
    
    '**************************************Main Program******************************************
    ' Wait for USB input
    idleloop:
    	USBService	' Must service USB regularly
    	cnt = 1	' Specify input buffer size
    	USBIn 3, buffer, cnt, idleloop
    
    ' Message received
    	Toggle LED
    
    outloop:
    	USBService	' Must service USB regularly
    	USBOut 3, buffer, cnt, outloop
    
    	Goto idleloop	' Wait for next buffer
    
    
    END

  5. #5
    Join Date
    Aug 2005
    Posts
    57

    Default

    Comment out INCLUDE "18F4550.BAS and add the following files to the project folder.It compiled fine for me and connected to the pc usb,but your code only flashes an led.
    CDCDESC.ASM
    usb18.asm
    18F4550.BAS
    USBDESC.ASM
    usb18.inc
    usb18mem.asm

  6. #6

    Wink

    Thank you got it running, the problem seemed to be that my pic basic pro was installed in PBP246 and not PBP as one of the references needed it to be, Just fixing the path seemed to repaired everything

  7. #7
    Join Date
    Dec 2008
    Posts
    48

    Default USBIN Question

    Have a very basic question that I want to confirm before going forward...

    In the PBP manual, USBIN is described as:

    ++++++++++++++++++++++++++++++++++
    USBIN Endpoint, Buffer, Countvar, Label

    Get any available USB data for the Endpoint and places it in the Buffer. Buffer must be a byte array of suitable length to contain the data. Countvar will contain the number of bytes transferred to the buffer. Label will be jumped to if no data is available.
    ++++++++++++++++++++++++++++++++++

    It was my understanding that with or without data, that this function always went to Label. Then within Label we perform a test to see if Buffer has new data and route execution from there.

    However, the way that the PBP manual describes it is that if no data is input, then program execution jumps to Label.

    Which one is it? Does this function always go to Label after reading 8 bytes (or however many specified during HID config. and specified in CountVar) even if there was or was not any input? Or, does this function only jump to Label when no bytes are read from the bus?

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