PDA

View Full Version : issue with serin and serout



oldcarguy85
- 1st August 2007, 00:53
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

oldcarguy85
- 1st August 2007, 01:59
o by the way... i'm using PORTA.0 for input and PORTA.1 for output

mackrackit
- 1st August 2007, 03:58
http://www.picbasic.co.uk/forum/showthread.php?t=561

oldcarguy85
- 1st August 2007, 04:04
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

mackrackit
- 1st August 2007, 10:28
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.

oldcarguy85
- 1st August 2007, 15:59
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

oldcarguy85
- 1st August 2007, 16:10
I GOT IT!!! it needed to be inverted. 38774 for inverted 38400. thanks for the help!

mackrackit
- 1st August 2007, 16:23
Here is some info on Baud Rate. http://francis.courtois.free.fr/jc1/serial/Basics/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.


SERIN2 PORT?.?,84,[your DATA]
Will receive at 9600,Driven, True, no parity.

mackrackit
- 1st August 2007, 16:29
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?

oldcarguy85
- 1st August 2007, 22:43
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

oldcarguy85
- 2nd August 2007, 00:17
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

mackrackit
- 2nd August 2007, 04:32
GREAT!!!
Now I need to do some studying :(