PDA

View Full Version : USB CDC Communications for Dummies!



Squibcakes
- 28th February 2007, 08:11
Want to communicate with your PIC via USB?
Want to install a virtual Commport on your PC?
Want to send serial commands to your PIC?

Its REALLY easy! Here's how.

Get yourself a PIC18F2455/2550/4455 chips that has USB support. And connect the Usb to to your PIC as shown below.

Note if using the USB bus power to power your pic remember that the max current your pic circuit can draw is 100ma! Anymore and you may blow your usb port! If in doubt stick in a fuse, or use external power.

For this demo though you can safely use the Bus Power. Mecanique has a good circuit diagram you can follow here. http://www.mecanique.co.uk/products/usb/schematic-large.gif

Pin Name Cable color Description
1 VCC Red +5 VDC (Vdd)
2 D- White Data - (RC4)
3 D+ Green Data + (RC5)
4 GND Black Ground (Vss)

Once your hardware is setup follow on....

STEP ONE.

In your PBP folder, copy the entire contents of the USB18 folder into a new folder where you store your pic programs;

eg... copy c:\pbp\usb18\*.* c:\cdcdemo

STEP TWO.

Open the USB descriptors file (called USBDESC.asm)
There are three lines of code in there, change the ; so that CDCDESC.ASM is used.



; include "MOUSDESC.ASM" ; USB descriptors for mouse demo
; include "JADESC.ASM" ; USB descriptors for Jan Axelson's demo
include "CDCDESC.ASM" ; USB descriptors for CDC demo

STEP THREE.

Copy this code and save it into the c:\cdcdemo folder and then compile using pbp.



DEFINE OSC 48

Buffer VAR BYTE[16]
Cnt VAR BYTE
B0 VAR BYTE
B1 VAR BYTE

ADCON1 = 15 ' Set all I/Os to Digital
CMCON = 7 ' Disable Comparators
Cnt = 16

USBInit ' Initialize USART

for b0 = 0 to 15
lookup b0,["USB CONNECTED!",10,13],B1
BUFFER(B0) = B1
NEXT B0

' Main Program Loop
Loop:
USBService ' Must service USB regularly
USBOut 3, Buffer, Cnt, loop
goto loop
end


When you compile the above program, PBP fuses the USB18 files in youe cdcdemo folder to generate the neccessary .HEX file. Viola!!
run your progam.

Windows will detect the PIC as a USB device and install the Microchip CDC driver.

STEP FOUR.

Open up Hyperteminal and select the virtual comport that was just installed. you should see USB CONNECTED! repeated.

Congratulations, you can send data from the PIC to the PC via a quasi Serial connection.

Ok How about sending and receiving data?

Program this code below into your pic:



buffer Var Byte[16]
cnt Var Byte
LED Var PORTB.0

Define OSC 48

USBInit
Low LED ' LED off

' 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

Again open Hyperterminal and the PIC will echo back the characters that you type (one byte at a time).

Try sending a large text file. Does it keep up?

Wow your becoming an expert now aren't you! ;)

Stay Tuned....
Squib

Bruce
- 28th February 2007, 20:43
Nice work Squib...;o}

T.Jackson
- 1st March 2007, 07:22
Nicely done. Worth a vote...

It would be great to see a lot more practical examples posted. Even better if there's an electrical schematic included as well.

Best Regards,
Trent Jackson

mister_e
- 1st March 2007, 15:38
http://www.mister-e.org/Pics/Awesome.gif

Pic_User
- 1st March 2007, 20:17
Beautiful, step by step “how to” piece of art. Thank you Squib. Nicely done.
-Adam-

vacpress
- 3rd March 2007, 00:47
thanks squib!

you are great.

ricgar
- 15th November 2008, 10:54
Hi Squipcakes

I've followed your instructions for this post and built the schematics attached which are very similar to yours posted (see attached). But once compiled and loaded onto the chip, the chip's power led lights up but the diagnostic led's don't and the PC doesn't even see a device attached to the system. I've checked my connections and they all seem fine. I have also attached the files used to make the hex and the hex (file is the mycdc.hex). I'm using a PIC18f2450 (not the same as in the schematics but same pinning)

What could be the problem??

Thanks

kirtcathey
- 31st December 2008, 02:04
Hi All. Thanks in advance for the help.

I am in a similar situation as the respondent above. Have setup everything with an 18F2550 and when plugged in, device not recognized error appears in XP. Where are the CDC drivers mentioned? A lot of the posts above applaud the project, but when a real implementation question is asked, it gets quiet.

Please, throw the dog a bone!

Regards,
Kirt

kirtcathey
- 31st December 2008, 04:28
Okay, I have got my problems down to matching VID and PID numbers in the mchpcdc.inf file and the VID and PID numbers burned on the PIC (18F2550).

Have looked in cdcdesc.asm, but don't know where to find these values.

Any help?

kirtcathey
- 31st December 2008, 05:02
Well.... I figured out the PID and VID stuff... The values in the cdcdesc.asm file and the values in the inf file of the driver (CDC this time) you are using must match.

After confirming this, XP still recognizes that a USB device is attached, but when I go to install the CDC driver, an XP dialog that says hardware information cannot be found appears.

Any help?

arniepj
- 31st December 2008, 23:48
Its been awhile since I went through the same project, but I don't think you need to modify those files.The pic config settings needs to be correct though.I have attached a project folder with files I did once I had it working.Look through the the files for possible clues,primarily the .bas for the config settings.
It uses a 4mhz crystal.
Good luck

sputnik77
- 1st January 2009, 01:11
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.

kirtcathey
- 1st January 2009, 01:59
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....

Darrel Taylor
- 1st January 2009, 03:24
If it compiles ... The number one cause of USB failure, is improper Oscillator Configurations.

For 4Mhz Crystal ...
@ __CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
For 8Mhz Crystal ...
@ __CONFIG _CONFIG1L, _PLLDIV_2_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
For 20Mhz Crystal ...
@ __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 ...
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. :)
<br>

kirtcathey
- 1st January 2009, 04:22
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

kirtcathey
- 1st January 2009, 04:31
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

Darrel Taylor
- 1st January 2009, 04:59
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. :eek:

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.

kirtcathey
- 1st January 2009, 05:23
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.:o

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

Darrel Taylor
- 1st January 2009, 05:27
There we go. That one must be #3 :D

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

kirtcathey
- 1st January 2009, 05:42
Awesome!! That was number 3! Still with the OSC define statement, but will put that in for completeness sake! All works. Will post a detailed 'my experience' in a few.

kirtcathey
- 1st January 2009, 08:24
Okay.... I got this puppy working with a bit of help from Darrel through the posts that lead up to this.

Attached is the MPLAB project file and supporting files. The biggest stickler has been getting the configurations correct for the oscillator selection. So the rule going forward for my projects is to comment out the configuration statements in the PBP devicexxxxx.inc files and declare them in the program.

Enjoy! Will be looking at this often as now I am moving onto inputs and other device profiles.... hopefully!

sputnik77
- 2nd January 2009, 07:17
I know to look out for all of the above and im very careful with setting configs on any 18 series device as there is a lot to them, however none of the above is my problem.

I cannot even get a confirmed working hex file to work without the dredded "Unknown Device" error, with EXACT hardware even.

Ive tried many different cables, ports, PC's etc. to no avail.

I always use .47uF caps on VUSB, as I have a hundreds of them.

Im about done with trying to get USB working and just continue on with the FTDI solution.

kirtcathey
- 3rd January 2009, 00:14
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?

kirtcathey
- 3rd January 2009, 00:52
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?

arniepj
- 3rd January 2009, 04:34
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/showthread.php?t=7372.If you think the CDC demo was fun,Hid is even better.

Andre_Pretorius
- 3rd January 2009, 15:47
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

:confused:


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

arniepj
- 3rd January 2009, 17:28
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

Andre_Pretorius
- 3rd January 2009, 20:48
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

kirtcathey
- 4th January 2009, 12:33
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?

sputnik77
- 5th January 2009, 01:48
Do any of you have a working hex for a 2550 on a 20MHz crystal that I can try?

I have tried everything I have found and still cannot get anything to work. I always get "Unknown Device" error no matter what.


The vendors of the compilers really need to give more concise information on USB communications.

kirtcathey
- 5th January 2009, 02:30
I was consistently getting USB device recognition when I connected, but ended with an unknown device when I did not have the configuration directives set appropriately. Read the above thread between Darrel and myself. Or, you can put in a 4MHz chip and just use the code I posted a couple days ago...

sputnik77
- 18th January 2009, 00:04
OK, I was finally able to get this working.

I was using the USBTEST files above.

I added the extra configs for the write protect stuff that was not in the code and VOILA!!!, it works now.

It seems to be an issue with the PicKit2. It barks at you if those configs are not included, it usually isnt an issue as long as the important ones are defined. However in this case I assume since they were missing , the PicKit2 changed some of the needed configs to something incompatible for some reason.

This should not be the issue, however it works. I removed the extra configs and it doesnt work, add them and its just fine!!!

Now to figure out how to get data INTO the pic.

sputnik77
- 19th January 2009, 07:30
Also, for 20mhz crystal/resonator, you MUST change the osc type to HS instead of XT.

HS will not work on 4Mhz, and vise versa.


SO,
here is what to do to get it working, "for sure". It seems to work for some with different setting however.

Ensure PPLDIV is 1 for 4Mhz, 5 for 20MHz
Ensure osc type is XT for 4MHz and HS for 20MHz
Include ALL config options.

After experimenting fpr days on end these seem to be the things that affect it most, for me anyway.

sputnik77
- 20th January 2009, 00:39
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?

I have some of the same questions. What IS and endpoint anyway???


In my findings the above example from the manual is backwards. It will only jump to the label if the buffer is FULL. It seems to sit and wait until the specified number of bytes have been received.

test153
- 6th February 2009, 00:28
Note if using the USB bus power to power your pic remember that the max current your pic circuit can draw is 100ma! Anymore and you may blow your usb port! If in doubt stick in a fuse, or use external power.

As far as I know a USB 2.0 device can draw upto 500mA once communication is established and the host grants the request for drawing more power, otherwise the device is only able to get 100mA from the host. I doubt that you will blow the USB port if you draw more then 100mA.

ricgar
- 14th February 2009, 18:59
Hi Guys

I'm pretty new to all of this, but here's my attempt.

I've attached a schematic of the device i am using.

What i am attempting to make here is some sort of USB to Serial Port Converter.

The code i loaded onto the chip is as follows:


'************************************************* ***************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2009 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 2009/01/02 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
@ __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H
'_CONFIG1H, _FOSC_XTPLL_XT_1H
@ __CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_28_2L & _VREGEN_ON_2L
@ __CONFIG _CONFIG2H, _WDT_OFF_2H
@ __CONFIG _CONFIG3H, _MCLRE_ON_3H & _LPT1OSC_OFF_3H & _PBADEN_OFF_3H & _CCP2MX_ON_3H
@ __CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L

' ****************************** Configure Hardware *********************************************
trisb = %11111100
trisc = %10111111 ' Set TX (PortC.6) to out, rest in
spbrg = 25 ' Calculate ((CPU speed mhz/Baud)/16)- 1 25 = 115200 baud EX:((48000000/115200)/16)-1
rcsta = %10010000 ' Enable serial port and continuous receive
txsta = %00100000 ' Enable transmit and asynchronous mode/brgh = 0 bit 2
baudcon =%00001000 ' Bit3 = 1: High speed usart 16 bit

'***************************** Variables ******************************************
USBBufferTX Var Byte[1]
USBBufferRX var Byte[1]
USBBufferCount Var Byte
SerBufferTX Var Byte
SerBufferRX var Byte[1]
BufferRX var Byte
SerBufferCount Var Byte
Indexer var byte
Xmit_Start var bit ' Start serial data transmission
Status_Bits var byte ' Status bits to Pc
Data_Delay var word ' Delay for dataout
Data_Out var word ' Data

Status_Bits = 0

LED Var PORTB.1

Define OSC 48

USBInit
high led
pause 1000
Low LED ' LED off
USBService

for Indexer = 0 to 0
USBBufferRX[Indexer]= 0
next

usbbuffercount = 1


main:
goSUB usb_rx
goSUB com_rx
goto main

' Transmit USB Data
USB_TX:
' TX buffer size
USBService
USBOut 3, serBufferrX, USBBufferCount, main ' Transmit data
RETURN

' Receive USB Data
USB_RX:
USBService
USBIn 3, USBBufferRX, USBBufferCount, exitsub ' Receive data if available,then exit
serbuffertx=usbbufferrx[0]
goSUB com_tx
return
'GOSUB Main


'Serial Receive

COM_RX:
hserin 1, exitsub, [bufferrx]
serbufferrx[0]=bufferrx
goSUB usb_TX
goSUB main

'Serial Transmit
COM_TX:
hserout [serbuffertx]
RETURN

exitsub:
return

Now this code compiles and i can connect via a hyperterminal to both the USB virtual and the physical Serial port. However if i enter anything in either of hyperterminals, it gives nothing and after a while of constant typing the hyperterminals start freezing on me. So i take it i've done something horrifically wrong.

Any suggestions?

mister_e
- 15th February 2009, 11:46
this section

COM_RX:
hserin 1, exitsub,
serbufferrx[0]=bufferrx
goSUB usb_TX
[b]goSUB main
I guess you want a Return there.

And when you deal with HSEROUT/HSERIN, you should use DEFINEs, unless, it will use default 2400 Bauds baudrate.

AND you must add DEFINE OSC 48 at the top of your code as well.

That should be enough to start ;)

ricgar
- 15th February 2009, 18:53
Hi Mister_e

Thanks for the response. I did already have a DEFINE OSC 48 already near start of the code, i have changed it to be return instead of GoSub Main. Thanks. As for your quote below


this section
you should use DEFINEs, unless, it will use default 2400 Bauds baudrate.



Would you be able to provide a bit more detail as regards the DEFINEs you mention, i have no clue what you mean by that.

Thanks

mister_e
- 15th February 2009, 20:17
DEFINE for HSEROUT are explained in the PBP manual :o

The serial parameters and baud rate are specified using DEFINEs:

' Set receive register to receiver enabled
DEFINE HSER_RCSTA 90h

' Set transmit register to transmitter enabled
DEFINE HSER_TXSTA 20h

' Set baud rate
DEFINE HSER_BAUD 2400

' Set SPBRG directly (normally set by HSER_BAUD)
DEFINE HSER_SPBRG 25

HSEROUT assumes a 4MHz oscillator when calculating the baud rate. To maintain the proper baud rate timing with other oscillator values, be sure to DEFINE the OSC setting to the new oscillator value.

In your case, the DEFINE list would look something like

DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 25 ' 115200 Baud @ 48MHz, 0.16%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

HTH

davids
- 13th June 2009, 18:46
DEFINE OSC 48

Buffer VAR BYTE[16]
Cnt VAR BYTE
B0 VAR BYTE
B1 VAR BYTE
led var porta.3

ADCON1 = 15 ' Set all I/Os to Digital
CMCON = 7 ' Disable Comparators
Cnt = 16

USBInit ' Initialize USART
start:
for b0 = 0 to 15
lookup b0,["USB CONNECTED!",10,13],B1
BUFFER(B0) = B1
NEXT B0
gosub send
ledl:
high led
pause 1000'(when i have delay nothing is working)
low led

afterled:
for b0 = 0 to 15
lookup b0,["closed led",10,13],B1
BUFFER(B0) = B1
NEXT B0
gosub send
goto start

send:
USBService ' Must service USB regularly
USBOut 3, Buffer, Cnt,send
return
end

davids
- 14th June 2009, 14:27
everything is working perfect i have connect it with labview but when i am using PAUSE 1000 nothing is working !!!!!!!

ScaleRobotics
- 14th June 2009, 15:26
Its the:



USBService ' Must service USB regularly
part. It must be serviced every 10 ms, or your communication will drop. So your pause 1000 is about 100 times too long. Some people have used Darrel's interrupt routines for the service interval. Here is one link:

http://www.picbasic.co.uk/forum/showthread.php?p=45302#post45302

davids
- 16th June 2009, 05:29
is theare any other way to make it working because i cannot to it working with this way....!!!!

ScaleRobotics
- 16th June 2009, 17:52
is theare any other way to make it working because i cannot to it working with this way....!!!!

There are lots of ways to make it work, but they all involve servicing the usb at a regular interval. Using Darrel's interrupts would do this in the background, and still allow you to use your Pause 1000. http://www.picbasic.co.uk/forum/showthread.php?p=30682#post30682 What keeps you from being able to use this method?

A not so good way to do it would be to create a loop.



For i = 1 to 250 'Loop 250 times X 4ms = 1000ms
Pause 4 'Pause 4 ms
USBService 'Service that USB connection
Next i


A better way to do it (if you still could not use usb service interrupt) would be to use a timer and control a "pause" with that.

Disclaimer: I have only once played with USB demo, so if anything I say is bogus, I am sure the experienced will correct this.

davids
- 3rd August 2009, 11:55
is it possible to control usb printer (label dymo) from pic 18f 4550???

Squibcakes
- 31st August 2009, 02:57
Nope, the Pic is a USB slave device, same with the USB printer.

So in a nutshell, Slaves (mice, printers, PIC) are connected to master devices (PC).

Darrel Taylor
- 31st October 2009, 03:31
If you are using PBP 2.50 or previous, disregard this post and use Squibcake's example at the beginning of this thread.
But you can still use USB_ASM_Service.pbp mentioned at the end of this post with Squibcake's example for easier servicing.

If you are using PBP 2.60, This might help.

With PBP 2.60, the way USB works has changed significantly.
You no longer need all those .inc .bas or .bal files for each chip, it automatically works with whatever chip you are using. The Ram usage is only 1 Bank now, which frees up a whole bunch of memory for your program. The asm routines have been optimized to only include what is needed for that protocol, which frees up more program space. All in all, they are just better.

And the best part is ... they're easier too.
There's an example from meLabs that works straight out of the box.<hr>
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.

When windows prompts you to install a driver, point it to the mchpcdc.inf file in the same folder.
Open a terminal program like HyperTerminal or equivelent and connect to the new COM port at any baud rate, it doesn't matter.
Press a key, and you should see "Hello World" returned.

Default configs are for a 20 Mhz crystal with 48 Mhz CPU (18F2455/2550/4455/4550 series).
18F13K50/14K50 must use 12Mhz crystal only.
0.22uF or higher capacitor must be on VUSB pin.

If it works, change the program as desired.
Don't change the program till it works ... it will work (if the hardware and configs are right).<hr>
NOTE: Long PAUSEs and USB don't mix.
Anything more than 10mS or so between servicing will cause the PC to disconnect the device.

Or you can add ...
INCLUDE "USB_ASM_Service.pbp" ; USB Init and Service interrupt routines
and not worry about USBINIT or USBSERVICE at all.

USB_ASM_Service.pbp
http://www.picbasic.co.uk/forum/showpost.php?p=78306&postcount=6

Cheers,

OzGrant
- 28th January 2010, 17:59
G'Day,
Used Mecanique cct(20M 18F4550) and PBP2.6 and after adding

@ __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H
and then enabling VREGEN config bit got the Windows USB Device Not recogised message.
Are there any other config bits that have to be changed.
Is it possible to get a hex file for this project so I can at lest check my cct.
tks

OzGrant
- 29th January 2010, 01:20
G'day (again)
My problem cured when I added a 10MFD cap on the two 18F4550 power pins.
I was using the USB 5v to power the card.
So can now start playing(at last) with USB.
Grant

f_lez
- 28th February 2010, 18:33
Windows sees a pic18 usb cdc device s inserted, but finds no drivers.

windows 7 32 bit

f_lez
- 5th March 2010, 18:34
yes the above error was me stupidly not showing windows device mangler where the right .inf file was, my bad...

But..

I am now doing a ' USBIN endpoint, buffer, count, nodatatloop ' every second or so, problem is when I send data to it, I only get it one byte at a time, so reading 'cat' takes 3 seconds......

count variable is always 1 if data present, so i get 1 three times then it returns to zero

surely I should get all 3 bytes into my buffer and a value returned of 3 for count.

I dont lose any chars from my text string in the terminal, i think it buffers and does some form of flow control, but when i copy a text file in a dos/command window, i do lose them, i get a count of one for the first 'C' but then a zero as 'at' have got lost before i got a chance to read them.

f_lez
- 7th March 2010, 12:18
Ok cant edit the above but it goes like this, if i send 'cat' with hyperterminal or putty i get 3 individual chars at the pic end so need to read 3 times, if i send it from a program written in vb6, i get a 'cat' in one loop/poll etc and a bytecount length of 3, as expected, hope no one else falls foul of this.

mackrackit
- 25th July 2010, 19:04
For anyone using this with WIN7 64 bit here is the *.inf driver file.
Remove the .txt

ScaleRobotics
- 31st December 2010, 20:39
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/showthread.php?t=13356&p=94292#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.

5042



' 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

LinkMTech
- 10th January 2011, 02:18
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. :eek:


; (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?

mackrackit
- 10th January 2011, 02:30
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/content.php?r=272-USB-SD-LOGGING

ScaleRobotics
- 10th January 2011, 02:49
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):



'************************************************* ***************
'* 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 *--------------------*

LinkMTech
- 10th January 2011, 15:58
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.

LinkMTech
- 10th January 2011, 16:19
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.

mackrackit
- 10th January 2011, 21:21
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...

LinkMTech
- 11th January 2011, 23:29
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!


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

Mark J
- 21st March 2011, 23:20
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!!!! :D)

Many thanks in advance,

Mark.

Scampy
- 22nd March 2011, 19:11
Just to add to Mark's post, we both know that a USB to serial cable works, but we're looking for a simplified modification than the current solution.

The original mod was designed to work with the parallel port, but later someone adapted this to serial using a three transistor / diodes and a handful of 10K resistors circuit. From what we can deduce it uses the DTR and RTS lines as level shifters, and the transistors as a simple switch so that it makes / breaks connections on the modified commercial PCB.

Hope that helps

Malcolm

cncmachineguy
- 23rd May 2011, 04:38
Trying to use 18F67J50. Trying to get this to work with a PIC_LCD3310. Followed all DT's instruction's for PBP2.60.

Using default configs, 20Mhz Xtal (I think). Program compiles fine. PK2 software writes it to the uP. Plug the USB in and nothing. No DE-DE. :(

Now I have been using this setup for other stuff, so I assume its not the hardware. Doesn't mean its not, but got to assume something. So first question, does anyone know if the default configs will work for this?

mackrackit
- 23rd May 2011, 13:57
The default config in the PBP directory looks correct for a 20MHz external.
Can you confirm that the chip is running at 48MHz?

cncmachineguy
- 23rd May 2011, 15:56
I can't confirm it right now, but I feel it is. I have been playing with receiving serial at 115K without any problems. But I was using configs set in code. I also tried those same configs, still nothing. I will double check all configs tonight.

Thank you for verifing the defaults should work. I know Darryl said not to mess with the code until it connected, but I think I can at least toggle a pin to make sure there is life, and at what speed.

mackrackit
- 23rd May 2011, 16:00
Post your code. Maybe there is something else.

cncmachineguy
- 23rd May 2011, 19:00
Here it is:


' USB sample program for PIC18F4550 CDC serial port emulation
' Requires PBP 2.60 or later
' 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.
Include "cdc_desc.bas" ' Include the HID descriptors
Define OSC 48
buffer Var Byte[16]
cnt Var Byte

OSCTUNE.6 = 1 ' Enable PLL for 18F87J50 family
Pause 10
USBInit ' Get USB going
' 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] = "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:
USBService ' Must service USB regularly
USBOut 3, buffer, 14, outloop
Goto idleloop ' Wait for next buffer

cncmachineguy
- 24th May 2011, 00:34
revisied code with a speed test added


' USB sample program for PIC18F4550 CDC serial port emulation
' Requires PBP 2.60 or later
' 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.
Include "cdc_desc.bas" ' Include the HID descriptors

Define OSC 48
trise.3 = 0
buffer Var Byte[16]
cnt Var Byte

OSCTUNE.6 = 1 ' Enable PLL for 18F87J50 family
Pause 10
'*****************************************
'--------------Speed test

speedtest:
toggle porte.3
goto speedtest

'--------------End test
'******************************************

USBInit ' Get USB going
' 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] = "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:
USBService ' Must service USB regularly
USBOut 3, buffer, 14, outloop
Goto idleloop ' Wait for next buffer


the results of the speed test: pin toggles at 3Mhz. To be clear, there is .3333uS between toggles. Now I don't feel like that is correct. lets see: 48Mhz=12Mips. So thats .08uS per instruction? So we are executing 4 instructions? Hmm, that doesn't sound right.

Ok, I will see if someone else can think better then I this evening

mackrackit
- 24th May 2011, 00:56
Might be a problem with the buffer size compared to the data being sent. They are different sizes.

Here is an example:


Buffer VAR BYTE[16]
Cnt VAR BYTE
B0 VAR BYTE
B1 VAR BYTE

ADCON1 = 15 ' Set all I/Os to Digital
CMCON = 7 ' Disable Comparators
Cnt = 16

for b0 = 0 to 15
lookup b0,["USB CONNECTED!",10,13],B1
BUFFER(B0) = B1
NEXT B0
USBINIT
' Main Program Loop
Loop:
USBService ' Must service USB regularly
USBOut 3, Buffer, Cnt, loop
goto loop

As for your speed test... my brain is ready to fuss out for the day also...

cncmachineguy
- 24th May 2011, 01:16
Hmmm.. I would think OS should still see it as a new device even if thats the case.

Well I am studing the schematic now, I am not sure I have the "CAP" on Vusb. But I can say this thing works with a USB bootloader no problem. Now does that mean winblows will see it? IDK

I see there are pullups on the data lines. And according to the datasheet, The internal pullups must be disabled. I have been looking at the include file, and I think there are being set.

I am just about to give up on this "pre-configured" answer. After all, it may NOT be the answer for this chip anyway. I will start looking at your solution to see if I can make that work.

mackrackit
- 24th May 2011, 01:24
The VUSB cap is a must.
I have not used the chip you are using. do you have a 4550 or 2550?

cncmachineguy
- 24th May 2011, 01:57
In case any one wants to look, here is the schematic and "manual (http://www.sparkfun.com/products/8855)" seeing how I am having trouble with anything tonight, (the pullups do not exist on the board), Maybe I should give this one a break for a bit.

No, I don't have any of those chips. :( I was hoping to be able to get this to work on a premade board. Seems like it should be possible. One thing I don't like, with the ready made code provided by melab, It takes more time to chase down what is ( or is not) going on.

Does it make sense that if I can use microchips USB bootloader, the hardware side of things are ok?

mackrackit
- 24th May 2011, 19:31
Looks like that board can be powered from the USB port. Is that what you are doing? If so, try powering it from another source.

Are you connecting the board for testing to the same machine PBP is on? If not, did you copy mchpcdc.inf to the PC?

cncmachineguy
- 24th May 2011, 22:47
So far I have tried powered from USB, and powered from PK3. It is on the same PC as PBP, but it is a win7/64 machine. I see earlier you posted an update for win 64 machines and that file. While I haven't downloaded that yet, I would still expect to get the de-dum when I plug in the cable. Even if win can't figure out what to do with it.

mackrackit
- 24th May 2011, 22:54
If the correct driver is not there the PC will not ding dong. It will just sit there or if you are lucky it will say it does not know what is plugged in. If you have PBP 2.6 you hqve the file needed for win 64. I think.

cncmachineguy
- 25th May 2011, 01:01
Well I have PBP 2.6C, So I think I must have all the proper files. I copied the entire contents of the USB18 folder to a new folder. started MCS, selected PIC18F67J50. Opened cdc_demo.pbp from the new folder. Hit compile, all was fine. programed chip. plugged in USB and waited. for at least 10 seconds. no indication from PC that I had plugged it in.

Now I listed these step just to be clear that is ALL I did. If I need to move a .inf file somewhere, or anything else like that, I have not done it.

On a side note, thought I would distract myself by installing VB 2010 express. Well that has also been FAIL! I am thinking I need to throw all this new crap in the trash and bust out an old dos machine. (yes I have some) I bet PBP will even run on that. :)

cncmachineguy
- 25th May 2011, 03:18
Found this on another forum:


The Microchip pic67j50 has a different USB ram location to standard USB devices. I know Les did do a conversion of the USB code for me and I got it to work with basic hid and CDC


Not sure if this could have anything to do with this. But at least I have a new place to look. Here I come RAM

cncmachineguy
- 26th May 2011, 01:03
Well some success today! Thanks to Walter (scalerobotics) and post #57 of this thread, I have a working CDC on a 18F47J53.

I am not sure I will keep trying to get this to work on the PIC_LCD3310, I will play with this for a while I think.

Thank you all who helped with this VERY painful task.

BTW, what speed should I think my "COM" port is running at, any ideas?

mackrackit
- 26th May 2011, 02:56
Just curious about post 57. What helped?

cncmachineguy
- 26th May 2011, 03:29
:eek:
:o I ment post 54! :o

Sorry for the confusion

mackrackit
- 29th May 2011, 17:27
Back to your question about speed....
I think it runs at USB speeds....


Universal Serial Bus Features:
• USB V2.0 Compliant
• Low Speed (1.5 Mb/s) and Full Speed (12 Mb/s)

Demon
- 30th May 2011, 22:51
Just tech notes about USB speeds:



The original USB 1.0 specification, which was introduced in January 1996, defined data transfer rates of 1.5 Mbit/s "Low Speed" and 12 Mbit/s "Full Speed". The first widely used version of USB was 1.1, which was released in September 1998. The 12 Mbit/s data rate was intended for higher-speed devices such as disk drives, and the lower 1.5 Mbit/s rate for low data rate devices such as joysticks.

The USB 2.0 specification was released in April 2000 and was standardized by the USB Implementers Forum (USB-IF) at the end of 2001. Hewlett-Packard, Intel, Lucent Technologies (now Alcatel-Lucent), NEC and Philips jointly led the initiative to develop a higher data transfer rate, with the resulting specification achieving 480 Mbit/s, a fortyfold increase over the original USB 1.1 specification.

The USB 3.0 specification was published on 12 November 2008. Its main goals were to increase the data transfer rate (up to 5Gbps), to decrease power consumption, to increase power output, and to be backwards-compatible with USB 2.0. USB 3.0 includes a new, higher speed bus called SuperSpeed in parallel with the USB 2.0 bus. For this reason, the new version is also called SuperSpeed. The first USB 3.0 equipped devices were presented in January 2010.
<SUP id=cite_ref-usb_3_article_8-1 class=reference></SUP>

http://en.wikipedia.org/wiki/Universal_Serial_Bus

dhouston
- 30th May 2011, 23:42
I don't know whether I'm too dumb or not dumb enough to grasp all the intricacies of CDC but, if I understand it, there are virtual serial port drivers for interfacing on the PC side. When these are used, there's likely to be a slight speed hit as the data needs to be 'translated' from its RS232-ish form before transmitting and the reverse is true when receiving.

This may not be noticed for normal communications but can be readily apparent when doing something like a firmware download which usuall includes short bits of data and CRC which is ACKed or NAKed from the embedded device. Of course, the faster the version of USB, the less this is a big factor.

mister_e
- 31st May 2011, 00:02
For CDC, baudrate is a meaningless parameter. You can set hyperterminal/vbSerialPort a whatsoever baudrate, the usb engine will emulate a serial communication as fast as it can

dhouston
- 31st May 2011, 00:26
For CDC, baudrate is a meaningless parameter. You can set hyperterminal/vbSerialPort a whatsoever baudrate, the usb engine will emulate a serial communication as fast as it canI'm not talking about transmission speed and I agree that baudrate has little meaning in this context. However, I have had a lot of experience downloading firmware files which might be as big as 64KB and there is a very noticeable difference between sending them via Serial->USB->Serial vs. sending them Serial->Serial with the latter being much faster as a result of the translation that must occur (on both ends). CDC should only need to translate on the PC end but I suspect there will be a significant speed hit never-the-less on certain applications.

mister_e
- 31st May 2011, 00:38
True that. CDC is really handy for older software unable to deal with USB, somehow easier to program on both side... but to me, IN 20XX... it still sucks.

I know your arguments... but ...Pure USB for me... all the way.

cncmachineguy
- 31st May 2011, 00:53
Steve, when do we get the pure USB for dummies? Both ends, PiC and PC??

mister_e
- 31st May 2011, 01:11
USBDemo was a kickstart for many. Time changed, PBP work tad different now, mcHID.dll/MCSP/EasyHid = somehow a dead duck, VB6 is a long time outdated thing, seems Jan Axelson code examples are not for everyone... :eek: so yeah I think it's about time.

I know how, I know something rock solid. Keyword: be patient...

(Still, there's LOAD of ressource/ready to go components/lib over the net on the PC side)

cncmachineguy
- 31st May 2011, 02:38
and I quote:



AAwwww come on guy, don't be lazy


After spending my weekend searching and reading. I have come to the conclusion there is in fact - tons of examples and ready stuff all over the net. But does this help if one doesn't know where to start? Even bought Jan's book to help me. And it did. Now I assume my weekends work would amount to 30 minuites for someone able to write a picmulticalc. So a quick VB express (cuz it free to all) example passing a byte or 2 back and forth. Nothing more then that as it will overwhelm those who don't get it. ( read as ME ME ME)

dhouston
- 31st May 2011, 03:05
Keyword: be patient...Ahh, you mean like waiting for the long-promised Tibbo EM500/GA1000 firmware. I'm down with that. :cool:

mister_e
- 31st May 2011, 04:49
After spending my weekend searching and reading. I have come to the conclusion there is in fact - tons of examples and ready stuff all over the net. But does this help if one doesn't know where to start? Even bought Jan's book to help me. And it did. Now I assume my weekends work would amount to 30 minuites for someone able to write a picmulticalc. So a quick VB express (cuz it free to all) example passing a byte or 2 back and forth. Nothing more then that as it will overwhelm those who don't get it. ( read as ME ME ME)

Everyone must start somewhere. Been there done that. I'm not more clever than anybody, but maybe I put more time & effort. I never found a magic potion to know everything and how to do things in a snap.
1) have a project
2) find information, read, digest them
3) try something
4) wash & rinse 'till it works

You CAN'T learn VB (or else) in a day. It take months, years. I learnt the hard way too. The more you do, the more you develop tricks....the easier it gets.

Don't give up!

mister_e
- 31st May 2011, 04:52
Ahh, you mean like waiting for the long-promised Tibbo EM500/GA1000 firmware. I'm down with that. :cool:
OH Really? Weird, It's the really first time I hear you about this long-promised Tibbo EM500/GA1000 firmware.

Ham Mucus

dhouston
- 31st May 2011, 04:56
OH Really? Weird, It's the really first time I hear you about this long-promised Tibbo EM500/GA1000 firmware.Yeah - I've probably made my point so I guess I'll go back to patiently waiting in silence.;)

mister_e
- 31st May 2011, 04:59
Humanity have been created in 7 days (or so) ... this ought to be a huge firmware :eek:


:D

cncmachineguy
- 31st May 2011, 05:14
Don't give up!

NEVER!!

I learned ASM with nothing more then the datasheet for my chip I wanted to use. So I won't give up. But its nice to have people to ask for help. No, I don't profess to even come close to knowing all there is to know about ASM, but I can get by.

mister_e
- 31st May 2011, 05:21
Keep it for yourself, I'll share a secret with you... I'm a forum addicted guy :D They are golden opportunities to learn faster... grab someone's problem, work on, find a solution... then someone else post an alternative, observe, wash & rinse.

Again... keep it for yourself :D

xkocik00
- 28th May 2013, 19:50
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.

xkocik00
- 31st May 2013, 09:55
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

tacbanon
- 26th October 2013, 11:37
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

mackrackit
- 29th October 2013, 11:03
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.

tacbanon
- 30th October 2013, 16:29
Hello macrackit, thank you so much for replying...I got it working now.

iw2fvo
- 7th November 2013, 08:54
Good day,
I have PBP 250_b running on a windows_7 64 bit.
What files are required in my PBP to update it to the 2.60 version and use the USB programs ?
Where could I download them ?
Thanks for helping
Ambrogio

mackrackit
- 7th November 2013, 10:29
You will have to go to MeLabs website and pay for the upgrade.

Ioannis
- 15th January 2014, 14:43
I know how, I know something rock solid. Keyword: be patient...

Hi Steve. Any news about this promised demo?

Ioannis