PDA

View Full Version : USB CDC help..



jchandir
- 22nd November 2008, 04:08
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.


@ __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

mister_e
- 22nd November 2008, 09:43
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

jchandir
- 22nd November 2008, 21:16
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

mister_e
- 22nd November 2008, 21:28
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 :o

jchandir
- 22nd November 2008, 21:46
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.

mister_e
- 22nd November 2008, 22:09
if you receive ASCII character, you shouldn't need to reconvert them... well I think :o

BUT BUT BUT... i should have see this line WAY before


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

jchandir
- 22nd November 2008, 22:23
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..