k-line(ISO9141, OBDii) checksum

Hello all, I am looking for some help on calculating the checksum for transmitting some data to the dashboard on my car. I have read some samples and can transmit them back into the dash and make it work. The part where I get stuck is if I try to change some numbers in the stream it will just ignore the frame because the checksum is incorrect.
I have a few examples of captures.
12 00 00 00 00 56 59 5F
7A 00 00 10 00 38 41 7D
From what I read it's a simple sum, but I can not get the checksum to come out correctly. Does anybody have and ideas on how this works?
Thanks!

Here you can find example code in C for the problem. It calculates CRC or checksum depending on the protocol used:

http://www.obddiagnostics.com/obdinfo/CRC.txt

Thanks for that. But how would I go about calculating it by hand?

mike_r:
I have a few examples of captures.
12 00 00 00 00 56 59 5F
7A 00 00 10 00 38 41 7D

What is the checksum there? 5F and 7D? Or something else?

Here is some code from a ecumodder google code.

// inspired by SternOBDII\code\checksum.c
byte iso_checksum(byte *data, byte len)
{
  byte crc=0;
  for(byte i=0; i<len; i++)
    crc=crc+data[i];
  return crc;
}

The checksum is indeed 5F and 7D.

From the code that you posted, it looks like you just add them all up and call it a day. Is that what I should be doing?

If that are your checksums neither the sum nor the CRC does work. Are you sure that this is ISO9141 traffic and not some proprietary stuff from the car producer?
How did you get the packet start and end?

I am about 99% sure that it is k-line. That is what the pin on the ECU is called that goes to the dash. Here is some more information that I have found. http://www.alfa145.co.uk/obd/14230-2s.pdf I can't quite follow what it's trying to say.

mike_r:

[quote author=Nick Gammon link=topic=107947.msg811100#msg811100 date=1338417722]
What is the checksum there? 5F and 7D? Or something else?

The checksum is indeed 5F and 7D.

From the code that you posted, it looks like you just add them all up and call it a day. Is that what I should be doing?
[/quote]

@mike, with my limited understanding I think the answer is yes.

Here is a bit about checksum supplied from your PDF:

If the message is
<1> <2> <3> ... ,
where (1 £ i £ N) is the numeric value of the ith byte of the message, then:
= N
where i (i = 2 to N) is defined as
i = { i-1 + } Modulo 256 and 1 = <1>

Also, if you don't mind, I would love to see your code and hardware information related to your k-line project. I am working on something similar but, for a motorcycle.

Here is the origin of the code I posted earlier. Look at the firmware section for shared code.
http://sterntech.com/obdii_avr_downloads.php

I don't have any code yet, as I am trying to figure out what I need to be able to interface it. As far as hardware goes, to interface K-line you will need a level converter. I have a freescale MC33660EF. That then connects directly into the micro's UART port. The tricky part is finding the baud rate. You can easily do that with an oscilloscope however.

I have a freescale MC33660EF

Thanks for reply. I think I have that chip, or at least one that works the same. I also found that a LM393 opamp can be used instead.

Here is another link you might find helpful. prj.perquin.com