PDA

View Full Version : 18F458 to PC communication Help



shawn
- 10th February 2007, 21:40
Goal is to create a data logger of some type.

I can not figure out how to comunicate from pic18F458 to pc. I've read and searched the forums and google and have found some good info. I just need help putting it together.

Question 1.
If I connect to the tx line of a DB9 com. port can I do that directly or do I need a RS232 connector. I would like to use a simple serout comand. It sounded like in the PBP manual a resistor was the only thing required but I've interpeted lots of info on both ways.


I'm using VB.net for my PC interface. I can program barely in VB.net but I am confident I can make this end work by following the guide posted here. http://www.codeworks.it/net/VBNetRs232.htm It is an aplication program to read and write to com ports using vb.net.
I have been using this program to test my PBP code on my pic. I am having no luck. To start off I am just trying to pass one byte of info to PC from Pic and have the aplication program read the one byte. My pbp code is as follows.

Define Loader_USED 1

Include "MODEDEFS.BAS"

S Var Byte
W Var Byte

s = 2
Main:
pause 2000

Serout PortB.1, 8, [#S]

goto Main

I'm using a 4Mhz crystal.

Question 2.
Is it my code or is my connection to the com port bad. Meaning do I need a RS232 translator in the circuit. I ran Portb.1 pin through a resistor and directly to tx line on com port.

Please any help would be apreciated.

Question 3.
What would be the best way to do this other than hardware usart. Using the program I downloaded from here. http://www.codeworks.it/net/VBNetRs232.htm

Thanks
Shawn

HenrikOlsson
- 11th February 2007, 15:16
Hi,
On the hardware side it usually works by connecting the PIC pin directly to the COM port thru a resistor just as you've done. However, you say you have it connected to the TX-pin which is pin 3 on a 9-pin com port. You should have it connected to the RX-pin which is pin 2. (What value on the resistor?)

On the firmware side I think you have the SEROUT mode wrong. I'm not sure on this but try N2400 or T2400.

Try to get it working with hyperterminal or, if you use MicroCode Studio, the Serial comunicator first. Then go on and test the VB-code.

/Henrik Olsson.

mister_e
- 11th February 2007, 15:28
As you stated you're using the Bootloader and unless you want to add an additional serial PORT and/or save a MAX232, there's no reason to use SEROUT.

This said, if you don't use the Bootloader, i can't confirm it will never cause any problem if you leave the DEFINE LOADER_USED 1 line...

On most setup, a simple 1k resistor in serie work using the inverted mode (N2400).. if you don't forget to connect the PC and PIC gnd together...

If you're using the Bootloader, you MUST disable the DTR control line in your VB program or The MCLR will always be set to GND. Make sure you also disable the handshaking. As Henrik suggested, do some simple test in MicroCode Studio's Serial Communicator to begin.

Bruce
- 11th February 2007, 17:30
For a direct serial connection from PIC to PC, use one of the 'inverted' serial
modes. Through a max232 or other inverting type interface, use non-inverted
mode.

shawn
- 11th February 2007, 20:24
Thank you all for your reply. Lack of sleep a bit of frustration and a little lazyness leads to disaster. You are all right and helpfull. I had the tx and rx lines reversed on the DB9 connector. I not sure how or why I triple checked that but I guess it needed checked 1 more time. I had the wrong serout config also. I've got it running now Thanks Again. I need to figure out the usart hardware on the pic next but not until I jump into the VB side for receiving.