I know I shouldn't double-post, but the other one was becoming obscene.
Okay, so, I've looked over the code and noticed a few things:
- You're using pins 2-3 for the K-line. You'll need to re-wire this to use the UART Tx/Rx pins 0-1 in order to make this work. ISO doesn't have any tolerance for baud rate issues, and the assumption that all you have to worry about is the overhead for digitalWrite is false. (You're in a for-loop, which means there's also compares, branches, etc. happening.) The fact that ATMega168 (or ATMega8) has a UART is a blessing, not a curse
- I was so happy to see the #defines at the top describing the PIDs, and then in other places in the code, there are constants without names (for(i=0; i<3+1+1+len; i++), for example) where the 3, 1, and 1 could be described with descriptive names rather than with long comments ahead of time -- extra #defines are free
I think once you guys use the UART, you'll find yourself very close. I did look and it appears that RS232 uses the same polarity on its bits as ISO-9141, so it should really be as simple as plugging into the UART, adding the line
Serial.begin(10400);
under
// switch now to 10400 bauds
and changing the reads and writes to the respective Serial calls.
Give it a shot when you get a chance