CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

setting up the pic 18f4550 for usb

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
madtoilet



Joined: 02 Apr 2008
Posts: 36

View user's profile Send private message

setting up the pic 18f4550 for usb
PostPosted: Tue Apr 22, 2008 1:54 pm     Reply with quote

Hi,

i'm back. I am now trying to configure my USB pic to transmit a string of data from the pic to the PC.

I am only familiar with using the

#use rs232 code

how do i configure it to use the USB ports properly?
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Tue Apr 22, 2008 2:27 pm     Reply with quote

hi, you can use virtual serial port - CDC, which is the simplest way. It behaves like a common RS-232 serial line
check ex_usb_serial.c out
madtoilet



Joined: 02 Apr 2008
Posts: 36

View user's profile Send private message

PostPosted: Wed Apr 23, 2008 1:28 pm     Reply with quote

hey, thanks for the feedback.

the code used in the example is
Code:

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)


i was wondering whether the baudrate matters. I'm unfamiliar with alot of USB stuff. Is there a particular baudrate the pc uses for the USB?
pattousai



Joined: 23 Aug 2006
Posts: 37

View user's profile Send private message

PostPosted: Wed Apr 23, 2008 2:13 pm     Reply with quote

well, i'm not the best guy to say anything, but the usb is a totally different protocol... you do not use the
Code:

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

unfortunately, that's all i can say to you :/

by the way,

meereck, you said that


Quote:

you can use virtual serial port - CDC, which is the simplest way. It behaves like a common RS-232 serial line
check ex_usb_serial.c out


how this work's out? it transforms from usb to rs232?

if i have any device (a cellphone, for example) that only communicate by the usb, i can use this CDC approach?

thanks very much
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Wed Apr 23, 2008 4:09 pm     Reply with quote

CDC emulates a serial line over the USB. At the PIC side, you use function like usb_cdc_putc and usb_cdc_kbhit() for sending data to a PC.
At the PC, the CDC device is installed as a virtual serial port. That is, within your PC application, you just select the proper COM port, and receive and transmit data like over a common serial port.
madtoilet



Joined: 02 Apr 2008
Posts: 36

View user's profile Send private message

PostPosted: Wed Apr 23, 2008 4:37 pm     Reply with quote

I'm quite confused.

so it emulates the serial line, so i don't have to be concerned for the baud rate?
kamputty
Guest







PostPosted: Wed Apr 23, 2008 4:59 pm     Reply with quote

madtoilet wrote:
I'm quite confused.

so it emulates the serial line, so i don't have to be concerned for the baud rate?


You do have to be concerned about the speed. Even though the usb emulated the serial, you still need to specify the settings to it can communicate to the "other" side of the serial cable!
Ttelmah
Guest







PostPosted: Thu Apr 24, 2008 2:42 am     Reply with quote

This actually gets quite complex!.

At the PC 'end', you see a com port. This has all the normal options for setting baud rates etc.. However these don't change anything physical about how the interface is handled. Instead if you set (say) the baud to 19200bps, a _message_ is sent across the USB interface to the device, saying effectively 'baud has been set to 19200'. The device at the other end can then decide what to do with this. So if you setup a PIC this way, and wanted to data to actually 'come out' of the chip as if this was a 'real' com port, then you would change the baud rate of this external interface, to match the requested speed. This is what happens on the little USB-RS232 adapter cable assemblies. However you don't have to actually do anything. The comms to/from the computer, are being handled as USB 'packets', sent normally at 12Mbps. So if the PIC is just using the data internally, it doesn't have to do anything at all about the speed (or parity etc.) requests. It can just accept that the data will arrive at whatever speed the PC sends them, and handle them as fast as it can, or send data back as fast as it wants. The actual speed available, is limited to about 1Mbps for such devices (basically, the Windows driver, tries to ensure that if there are multiple such devices on the bus, all 'get a chance', and with the maximum time 'slot' allowed for this interface by the Windows driver, and given the packet sizes, overhead etc., this is about the best possible.

So, the data transfer will take place faster than any normal RS232 link, and with the speed remaining constant, whatever the baud rate is set to.

_If_ you need to talk to an external device, then the PIC code will have to handle the packet telling it what speed to use, and change it's settings to talk to this device. However for applications which don't have an external connection like this, you can forget about baud rates.

Best Wishes
yanthi
Guest







ex_usb_serial.c
PostPosted: Tue May 27, 2008 6:04 pm     Reply with quote

After i load the program ex_usb_serial.c in pic 18F4550, my pc can't detect the usb at all. Any solutions....probably with the coding....

thanks
sella
Guest







ccs coding for usb
PostPosted: Tue May 27, 2008 6:20 pm     Reply with quote

when i tried to open hyper terminal after loading the ex_usb_serial2.c,it says "unable to open comx, please check your port settings".What should i do? Please help me.....

thanks
peuchele
Guest







unable to open com
PostPosted: Thu Jul 03, 2008 3:55 pm     Reply with quote

Hi, I had the same problem "unable to open com..." and I fixed it by setting the proper bit settings before programming the PIC, for example disable the WDT (for the CDC example), setting the correct clock speed, etc.
I know that maybe it is too late to post the response, but it may help someone else in the future...
Fernando
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group