Simple 1 Byte Checksum Method


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Jul 2013
    Posts
    41

    Default Simple 1 Byte Checksum Method

    Hello,

    I need to encode/decode a simple 8Bit Checksum based on a transmitter which has no documentation.

    Apparently, it is just using the last 2 Bytes of a 10 Byte packet to calculate it.
    (Figured THAT out by dumb luck.)

    Using a Logic Analyzer, it appears it is the simple sum of these two bytes.
    Payload[8] + Payload[9] = CheckSum
    5 + 2 = 7
    245 + 2 = 247
    53 + 1 = 54
    54 + 1 = 55
    21 + 2 = 23
    etc, etc,

    I have not been able to capture what happens over 255 but assume it must roll-over somehow?

    Browsing all the "CheckSum" threads here, I think the code may be something like the following:
    ----------------------------------
    Payload VAR BYTE[11]
    (Payload elements...)
    CheckWord VAR WORD
    CheckSum VAR BYTE


    CheckWord = Payload[8] + Payload[9]
    CheckSum = CheckWord.byte0 ^ $FF '<--- This?
    'CheckSum = CheckWord // 256 '<--- Or That?
    -----------------------------------


    Any ideas?

    Thanks,

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Simple 1 Byte Checksum Method

    would it not be easier to

    if Payload[10] -( Payload[8] + Payload[9]) > 0 then goto badckecksum

    or conversely

    Payload[10] =Payload[8] + Payload[9] to create chksum
    Last edited by richard; - 6th March 2015 at 19:34. Reason: not sure if creating or checking chksum

  3. #3
    Join Date
    Jul 2013
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Re: Simple 1 Byte Checksum Method

    Right. That's simple.
    Problem is when they add up greater than 256 becoming a WORD.

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Simple 1 Byte Checksum Method

    it can't become a word if the var is declare as a byte it just rolls over .
    Payload var byte[11]

    btw the transmitter its not a fineoffset weatherstation ?

  5. #5
    Join Date
    Jul 2013
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Re: Simple 1 Byte Checksum Method

    It can't be that simple?
    What if there were more than 2 Bytes like 10?

    No it's not a weatherstation, more like a entry door counter.

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,389


    Did you find this post helpful? Yes | No

    Default Re: Simple 1 Byte Checksum Method

    a byte can hold a value between 0 and 255
    255 + 1=0
    255+10=9
    255+255+255+1= 254

  7. #7
    Join Date
    Jul 2013
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Re: Simple 1 Byte Checksum Method

    Richard,

    Wow!
    That is so clean and easy.
    (I do have a tendency of making things complicated.)

    Thank you very much!

    Jay Zebryk
    Southbridge, Massachusetts

Similar Threads

  1. Reading a speed sensor best method?
    By davewanna in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 27th January 2012, 02:37
  2. Calculate Byte Value Checksum in PBP Pro
    By Pedro Pinto in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 8th July 2009, 22:50
  3. ASM Addressing method help needed
    By sougata in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 28th January 2007, 17:01
  4. Current Calculation Method
    By DynamoBen in forum Off Topic
    Replies: 4
    Last Post: - 16th September 2006, 09:21
  5. Which is the method to use
    By dtit in forum General
    Replies: 0
    Last Post: - 18th January 2005, 09:53

Members who have read this thread : 1

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