18F458 to PC communication Help


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2004
    Location
    nebraska
    Posts
    79

    Default 18F458 to PC communication Help

    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

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521

    Default

    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.

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    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.
    Last edited by mister_e; - 11th February 2007 at 14:36.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405

    Default

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

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Dec 2004
    Location
    nebraska
    Posts
    79

    Default

    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.

Similar Threads

  1. Replies: 11
    Last Post: - 12th July 2008, 02:36
  2. Communication between PC and PIC16f876
    By knsteam in forum Serial
    Replies: 11
    Last Post: - 26th June 2007, 09:59
  3. Replies: 5
    Last Post: - 20th March 2006, 01:34
  4. Pic18F4455 to PC communication RS232
    By anmproj in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th July 2005, 02:32
  5. Interrupt and Serial communication to PC.
    By obaskirt in forum mel PIC BASIC
    Replies: 2
    Last Post: - 17th June 2005, 20:01

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts