PDA

View Full Version : Did I get the right device? USB-Serial



wdmagic
- 19th June 2013, 03:29
I just ordered a USB TTL cable on ebay, hoping its what I hope will let me connect USB from PC directly to PIC with serial communication, if someone could give me an idea on the Code I should use or any links. also with this unit is it possible to send say 32bits of data into 4bytes of variables? Eventually I want to use the USB Option on the 18F4550 but I need to learn to Interface with a serial port first.

The Ebay item I just ordered LINK (http://www.ebay.com/itm/271211061815)

I dont want to have to use and translation chips, I want to go strait from usb to PIC. So did I order the right kind of cable?

HenrikOlsson
- 19th June 2013, 06:18
Hi Chris,
I can't look at the link you've posted as I'm currently on a restricted network so this is more in general. If I'd venture a guess that cable is a "standard" USB to serial converter. When connected to the PC and its drivers are installed it'll look to Windows as just another COM-port. The software on the PC and on the PIC will be exactly the same as if you were using a real COM-port.

You say that you don't want to use any converter chips but that's exactly what that sort of cable is - it contains a USB-serial converter (like the FT232 for example). Now, some cables/converters outputs true RS232 levels meaning you'd need a RS232<->TTL level translator chip (like the MAX232) but since you mention USB to TTL I'd think your particular one outputs TTL so it should be OK to connect it directly to the PIC.

As for going "true" USB that's a completely different thing compared to "serial over USB". I haven't yet ventured in the world of USB (I tried once and failed...) so I'm not the right guy to give advise on the subject.

/Henrik.

wdmagic
- 19th June 2013, 21:21
thanks for the quick reply henrik,

heres the data on it.

1m PL2303HX Download Cable USB To COM USB to TTL Converter Cable
Features:
•Built-in TTL COM PC-PL2303HX Chip.
•Standard USB type A male and TTL 4 pin connector
•Simple and Easy way to give USB support to your designs
•Available for Linux, Mac, WinCE and Windows (XP, 2003), Vista Win 7

Pin Definition:
 Black cable GND
 Green cable TXD 
 White cable RXD
Red cable VCC

HenrikOlsson
- 19th June 2013, 21:57
Hi Chris,
Yes, now I'm on a "better" network so I took a look at the EBAY-link.
When you plug that cable into the PC and install the device driver it'll appear as another COM-port in Windows. You can find the driver on the Prolific PL-2303 (http://www.prolific.com.tw/US/ShowProduct.aspx?p_id=156&pcid=41) site (which is the USB<-> chip used in the cable).

/Henrik.

wdmagic
- 20th June 2013, 01:32
thanks, i will be using VB.net to build the interface program, but I was wondering just to test it out.. I remember back in the days of DOS, you could do a command like

c:\12345678 >com1 ???
or
c:\copy test.txt >com1

something like that, I cant remember it exactly, but you could send a text string or file directly to a com port or lpt port. can you still do that?

also is it possible to send a large number of bits, say 32,48,64 and have it store them in a set of variables, for example


MYBYTE0 VAR BYTE
MYBYTE1 VAR BYTE
MYWORD0 VAR WORD
MYWORD1 VAR WORD

LOOPME:
SerialIN????
code to break up string in pieces and store in variables
GOTO LOOPME

my textbox on PC has 48 "1 & 0's" no spaces to be sent as an example

HenrikOlsson
- 20th June 2013, 06:21
Hi Chris,
Can't help with the command line interface to the COM-port, never seen that before. Doing serial coms in VB.net using the supplied serial port object is quite easy though. Just beware that Microsoft removed the serial port object from VB when they introduced .net and put it back in some later version. I believe all the Express versions have it if that's what you're using. It's been a long time since I played with VB.

On the PIC side there's no problem to receive "any" number of bytes. HSERIN can split the bytes up properly as it receives them or, if you're using an interrupt driven routine you can store the data in an array and split them up when everything is in. It all depends on how the data is formated, high or low byte first etc.

/Henrik.

wdmagic
- 20th June 2013, 08:56
ok Thanks, Ive got .net enterprise 2010, and Ive confirmed I do have the serial control, will have to do a bit of searching for some example code to start.
as for the pic side thats great news, I need to send a word at a time, the high byte determines which variable to store the low side byte. it would be great to be able to split it at 6/10 bits and convert the high 6bits to a single byte, and the low 10 to a single word. So...
"0000110000001111" would end up split up at "000011/0000001111"
Byte0 = 00000011
Word0 = 0000000000001111
Does this look like it might work?

HenrikOlsson
- 20th June 2013, 10:18
Hi,
Something like this might work then:


RawWord VAR WORD
Adress VAR BYTE
Value VAR WORD

HSERIN[RawWord.Byte1, RawWord.Byte0] ' Receive two bytes and store them in RawWord, high byte first
Adress = (RawWord.Byte1 & 252) >> 2 ' Get the 6 top bits and store them in variable Adress, 0-63. (The &-operation may not be needed)
Value = RawWord & 1023 ' Get the bottom 10 bits and store them in variable Value, 0-1023


/Henrik.

wdmagic
- 20th June 2013, 21:33
thanks, I will try that as soon as part gets here!

Charlie
- 21st June 2013, 08:54
If you are running Windows XP, then Hyper terminal will work. Alternatively, you can download a simple terminal program for free called Terminal (V1.9b is the latest). I would not recommend trying to start with developing both ends of the link at the same time. When it doesn't work first time (you know it won't), troubleshooting will be significantly easier if you know one end of the link is correct. YMMV