issue with serin and serout


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Aug 2007
    Posts
    13

    Default issue with serin and serout

    Hey there,
    I'm very new at this basic programming stuff, but here is my question. im working on an lcd project for my car that interfaces with the ECU. there is a data port on teh ecu to connect to. The ECU program has been modified such that you can send a byte and receive a byte back. depending on what i send i should get info about different sensor readings. This is a basic TTL interface and should not be too difficult. i am able to send data and recieve data with a laptop and a serial->TTL converter. However, my pic16f877 seems to be having issues with the communication

    here is the pertinent code:

    SERIN2 in_pin,ser_baud,[tempval] 'get input from computer
    serout2 me_out,6,[tempval] 'send this data to the ecu
    serin2 me_in,6,4000,loop,[test2] 'get the response from the ECU
    serout2 out_pin,ser_baud,[test2] 'spit it back to the PC

    this is basically whats in my main loop.

    i am able to communicate correctly with two computers hooked up with two ttl converters. So i know the communication should work. I think it has something to do with timing, such that possibly the PIC is recieving the data from the ECU before it gets to the serin2 command. im not sure. any help would be greatly appreciated. o btw the ECU operates at 38400 baud rate thast why theres a 6 there.

    thanks,
    Jordan Cary

  2. #2
    Join Date
    Aug 2007
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    o by the way... i'm using PORTA.0 for input and PORTA.1 for output

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Aug 2007
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    sorry i should have included more of the code. i already took care of turning everything to digital and turning the comparators off. made no difference. as i said the PIC communicates properly between two pc's. i connected one pc to the serial interface i have setup for the pic and then i used another max233 to connect another pc to my porta input and out and was able to send bytes between the pcs without a problem.

    thanks,
    Jordan

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Looking back at your first post and I am still not clear on a few things.
    ECU to PC = YES
    PIC to PC = YES
    ECU to PIC = NO

    You may want to look at the PBP manual, I can not find 38400 as a baud rate and 6 is 9600 for SERIN/SEROUT.
    o btw the ECU operates at 38400 baud rate thast why theres a 6 there.
    Others have talked about using a PIC with an ECU, I have not done so, beyond basic serial com I can not help. So the best I can suggest at this point is to double check the baud rates and if the data is true or inverted.
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Aug 2007
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    i was under the impression teh baud rate was simply a calculation, (1000000 / baud) - 20


    when i connected a PC to PORTA.0 and PORTA.1 it was able to send and recieve data at 38400 baud rate. actually now that u mention it, the one thing i DON't know is if the ECU wants the data true or inverted. i imagine true. how would i set it to inverted? the microcode reference suggests bit 14, but i'm confused how to set bit 14 ?

    thanks,
    Jordan

  7. #7
    Join Date
    Aug 2007
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    I GOT IT!!! it needed to be inverted. 38774 for inverted 38400. thanks for the help!

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Here is some info on Baud Rate. http://francis.courtois.free.fr/jc1/...BitFormat.html
    The formula you are looking at from the manual is for figuring bit time in microseconds.

    In the back of the manual, Appendix A, there is a table for SREIN2/SEROUT2.
    Code:
    SERIN2 PORT?.?,84,[your DATA]
    Will receive at 9600,Driven, True, no parity.
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    You got it while I was replying.
    I do not think I was much help, Now I am confused
    Would you mind posting the code that works so maybe I can learn something?
    Dave
    Always wear safety glasses while programming.

  10. #10
    Join Date
    Aug 2007
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    Well, it turns out i was wrong.

    i only tested it for a few minutes this morning, and upon further inspection this afternoon it turns out, while i was recieving data, the data was completely inaccurate. im very confused. all i know is the ECU should talk at 38400 8N1. i've tried a LOT of combinations and i can't figure it out.

    thanks,
    Jordan

  11. #11
    Join Date
    Aug 2007
    Posts
    13


    Did you find this post helpful? Yes | No

    Default

    OK FINALLY GOT ITTT!!!!! WOO HOOO. forgot to connect a common ground! i am an idiot! btw - 6 works perfect for 38400 8N1!

    thanks for the help
    Jordan

  12. #12
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    GREAT!!!
    Now I need to do some studying
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. PIC16f877 code crosses boundary @800h
    By inventosrl in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 6th April 2009, 22:03
  2. Advice-scrutiny for my serial controller
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th December 2008, 17:11
  3. Help with serin, serout, Manchester encoding
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 5th April 2007, 13:31
  4. Serial interface with RFID reader
    By brid0030 in forum Serial
    Replies: 8
    Last Post: - 23rd January 2007, 06:23
  5. SerIn and SerOut
    By Dwayne in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 21st July 2004, 15:54

Members who have read this thread : 0

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