USB CDC help..


Closed Thread
Results 1 to 7 of 7

Thread: USB CDC help..

  1. #1
    Join Date
    Nov 2008
    Posts
    9

    Default USB CDC help..

    Hey, this is my first post here to forgive me if I mess up. I am working with a 18f2550 running at 48 Mhz uising HSPLL. I succesfully used the CDC sample from PBP. MY problem is that I cant get it to work if I change the way I allocate the buffer array. I am simply taking a decimal number, converting it to a string, and sending it to the computer. Can someone tell me what I am doing wrong. It is the simplest thing and I dont understand whats wrong. The Terminal program just freezes as soon as I send something to the pic. I want to use this program to do ADC and send them to my computer.

    Code:
    @    __CONFIG    _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
    define LOADER_USED 1        ' USB Boot loader
    define RESET_ORG 1000h 
    Define  OSC     48
    
    buffer var byte[16]
    x var byte
    y var byte
    cnt	Var	Byte
    LED	Var	PORTB.0
    
    
    Pause 10
    
    	USBInit
    	Low LED		' LED off
    
    ' Wait for USB input
    idleloop:
    	USBService	' Must service USB regularly
    	cnt = 16	' Specify input buffer size
    	USBIn 3, buffer, cnt, idleloop
    	
    		Toggle LED
    
    
    y = 123 ; just a random number for test
    goto convert
    
    
    outloop:
    	USBService	' Must service USB regularly
    	USBOut 3, buffer ,6 , outloop
    
    	Goto idleloop	' Wait for next buffer
    	
    
    convert:
    	
    for x = 2 to 0 step -1
    buffer[x]=(y dig x) + $30' find digit & convert to ASCII
    next x
    end 
    buffer[3]=13
    buffer[4]=10
    buffer[5]=0
    
    goto outloop

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

    Default

    I really don't understand why people persist to use CDC while life could be easier and better using the real USB protocol...
    http://www.picbasic.co.uk/forum/showthread.php?t=5418
    Steve

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

  3. #3
    Join Date
    Nov 2008
    Posts
    9

    Default

    The reason I want to use CDC is because its already made, and I don't have to mess with VB. I don't know anything about it so i kinda wanted to start out slow and just have to work with PBP.. When i get better I will use the HIDmaker and figure out all that stuff. I have used you USBdemo and it works very well so I will study it later and try to figure it out. Does anyone know whats wrong with my code? please help.. thank you

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

    Default

    Just to make sure of everything
    You're using a 4MHz crystal (or resonator)?
    Which PC terminal software are you using?
    On the PC side, are you sending 16 character at the time?
    Are you using the Microchip bootloader? If so could you post your .HEX code? Not sure if Microchip bootloader work in CDC mode
    Steve

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

  5. #5
    Join Date
    Nov 2008
    Posts
    9

    Default

    I am using 4Mhz and I am using the serial comm in Micro code studios plus. I am not sending 16 bytes just pressing enter, but this works just fine when using the Cdc demo. I am using Microchip bootloader, and again this works just fine using the CDC demo from PBP. I don't have my hex code here since I am at work, I can do that as soon as I get home. I even tried servicing the USB more often and that didn't work either. I don't understand since the programs are identical, the only difference is how I set the buffer in my code. Thanks for your help. I only wish I was good enough to use the USB protocol and dll along with VB. Some day.

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

    Default

    if you receive ASCII character, you shouldn't need to reconvert them... well I think

    BUT BUT BUT... i should have see this line WAY before
    Code:
    for x = 2 to 0 step -1
    buffer[x]=(y dig x) + $30' find digit & convert to ASCII
    next x
    end 
    buffer[3]=13
    buffer[4]=10
    buffer[5]=0
    
    goto outloop
    remove that END and the problem should go forever...
    Last edited by mister_e; - 22nd November 2008 at 21:20.
    Steve

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

  7. #7
    Join Date
    Nov 2008
    Posts
    9

    Default

    OMG!! You are awesome, i cannot believe I didn't see that.. This is what i get for copying parts of other codes and putting it all together.. Thanks man.. I just posted in the Nokia LCD post. I have a problem and was wondering if someone could help me.. Can you take a look at it. Its in the Color LCD post.. Thanks again man..

Similar Threads

  1. USB CDC Communications for Dummies!
    By Squibcakes in forum USB
    Replies: 104
    Last Post: - 15th January 2014, 13:43
  2. USB Bootloader.
    By HenrikOlsson in forum USB
    Replies: 22
    Last Post: - 2nd May 2013, 02:46
  3. Simple USB Comms Problem
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 6th January 2010, 20:17
  4. One USB keyboard to Two USB Ports
    By picnaut in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th June 2009, 00:04
  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 : 1

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