Bit bang 5 baud with BS2 (on OBD2 ISO 9141)
n00b
Posts: 5
Hi all,
This is my first time posting on the forum. I've used the BS2 since 2005 but have not really done a lot with serial communication using SERIN and SEROUT (other than simple LCD displays).
Now I've got a new fun project which is to interface with the OBD2 connector in my Honda Civic. The difficulty right now lies in initializing the ECU, which requires transmitting HEX 33 at 5 baud.
According to the Stamp manual, the baudmode for the SEROUT command for 5 baud (assume 8 bit no parity inverted) would be 199980 which exceeds 65535, so that won't work. So, I thought I would manually create and time bits via the HIGH and LOW commands (which I later found out is called bit-banging), but I'm not confident that the timing is right and I don't have a scope to verify the signal. PULSOUT will not work either, as the bit length is 200ms (max is 131.07ms on the BS2)
I am using a MAX222 line driver to get the outputs up to RS-232 voltage, so the bit bang is sent through this chip, which probably makes things more tricky. So far I have not been able to get a response from the car's ECU... Though there could be other things wrong, does anyone have experience bit-banging at a super low speed like 5 baud? I'd be interested in knowing if there is a better method to pull this off. Thanks everyone!!!
I'm also surprised I was able to get the username "n00b" on the forums... who would have guessed?
-Bobby
This is my first time posting on the forum. I've used the BS2 since 2005 but have not really done a lot with serial communication using SERIN and SEROUT (other than simple LCD displays).
Now I've got a new fun project which is to interface with the OBD2 connector in my Honda Civic. The difficulty right now lies in initializing the ECU, which requires transmitting HEX 33 at 5 baud.
According to the Stamp manual, the baudmode for the SEROUT command for 5 baud (assume 8 bit no parity inverted) would be 199980 which exceeds 65535, so that won't work. So, I thought I would manually create and time bits via the HIGH and LOW commands (which I later found out is called bit-banging), but I'm not confident that the timing is right and I don't have a scope to verify the signal. PULSOUT will not work either, as the bit length is 200ms (max is 131.07ms on the BS2)
I am using a MAX222 line driver to get the outputs up to RS-232 voltage, so the bit bang is sent through this chip, which probably makes things more tricky. So far I have not been able to get a response from the car's ECU... Though there could be other things wrong, does anyone have experience bit-banging at a super low speed like 5 baud? I'd be interested in knowing if there is a better method to pull this off. Thanks everyone!!!
I'm also surprised I was able to get the username "n00b" on the forums... who would have guessed?
-Bobby
Comments
I'll post a schematic soon with labels. One thing to note is I eliminated the capacitor between pin 5 and 6 on the MAX222 in order to "fake" the output of the chip to 0v/+12v logic. Otherwise, it would follow the +/-12v typical RS-232 logic. This choice is based on other OBD2 ISO 9141-2 interpreting chips which don't seem to go negative voltage. This change seems to have no effect when talking between two MAX222 chips (can send and receive data fine at 10400 baud), but I can't tell if the OBD2 interface likes this or not.
At this time I'd like to only get feedback on the timing for a 5 baud bit bang... my wiring and voltage levels could have other problems.
I just don't want to take the easy road out and get an ELM323... If there's a way to initialize the ECU with a BS2 bit bang, I aim to figure it out! Thanks everyone.
Your Start bit is 200ms, your data bits high/low are 400ms ea., and your Stop bit is 200ms.
Ordinarily, a Start bit takes the same time as a data bit, likewise a Stop bit though they can range up to 1.5 bit times.
So, I think that your data bits should be 200ms (too).
I think the problem with my setup was the MAX222 simply is not supplying the right voltages for the ISO9141 protocol (0v, +12v). I still plan on posting all the code and (new) schematics once I get a chance. Thanks everyone!!!
$33 = $00110011
N00b,
The byte is transmitted lsb first as:
111111111101100110011111111111111 '
My question has to do with what the program does after the stop bit Usually the RS232 line stays in the STOP state after transmitting a byte. Is there something different about the ECU? This instruction puts the line in the START or BREAK state. You have,
1111111111011001100100000000000000000 ' <--BREAK!
You're right, that was also a flaw in my program. I have to keep reminding myself that the ISO9141 bus idles at +12V = logic 0. I'll post an update later tonight to show what the new program and schematic looks like.
So, lessons learned? First, I had to remember which way the bits are inverting (or not inverting), depending on if I was sending or receiving a message. That was confusing at the beginning. Second, timing is everything (not having a method of flow control or a very finite idea of the ECU timing was frustrating).
One weird thing... the checksum byte returned (B8) doesn't seem to be correct. Adding up bytes 0-6 gives 510, so I think the checksum byte should be 510-255 = 255 (FF). I need to do a little more work to figure that out.
The other disappointment is that only a handful of PIDs are supported for my car (2000 Civic DX). The only somewhat interesting parameter I can read in real time is throttle position sensor. I was hoping to get more things like MAF, intake temperature, etc., but it appears such data is not output by this ECU (I'm sure I can get it if I tap into enough of the wires and use a A/D converter, but that wasn't what I had in mind).
Anyway, I'm just glad I got it working. There did not seem to be any solid "how-to" on Parallax forums for reading OBD2 data, so I'm glad I could share my findings with everyone. I hope other people expand on this topic and post some of their own projects!
can everyone helm me to convert BS2 code to C / arduino code?
I have same case, but I do not familiar with BS2
thank you everyone
BR from java island