Checksum / CRC8 / CRC16


Closed Thread
Results 1 to 4 of 4
  1. #1
    treitmey's Avatar
    treitmey Guest

    Lightbulb Checksum / CRC8 / CRC16

    Has anyone written PICbasic Pro code for checksum?

    I would love reuse this code in a project I'm working on.

    or

    Does anyone know how to do this?

    Thanks

  2. #2


    Did you find this post helpful? Yes | No

    Default XOR is your friend

    Hello Treitmey,

    One way to perform crude (but effective) error checking is to XOR every character you send out the serial port with the character that was sent before it and store each calculation in a checkbyte (this is not technically a checksum).

    Immediately after you send out your last character you send out the checkbyte.

    At the receiving end the process is repeated. As each character comes in it is XOR'd with the character that came before it. Each calculation is stored in another checkbyte variable.

    The last character that is received must be the transmitted checkbyte.

    If the transmitted checkbyte agrees with the calculated checkbyte at the reciever then the message must be clean. If they don't agree then something must have went wrong during transmission.

    If something went wrong then the receiver must tell the transmitter that it has to resend it's data.

    It's not a bad idea to frame your packets with start and end characters. Make sure that there is no way that these characters could appear in the actual data.

    An example of this would be to send the data with a "(" at the start and a ")" at the end.

    Also, make your packets as short as is practical. Using long packets in a noisy environment makes for much slower communication, even at higher baud rates. This is because data corruption isn't detected until the packet has been completely sent. If it's corrupt then all that time has been wasted.

    Hope this helps you out.

    picnaut
    ---> picnaut

  3. #3
    treitmey's Avatar
    treitmey Guest


    Did you find this post helpful? Yes | No

    Smile Thanks

    Thanks, I didn't know it was that easy,... When I looked checksum up on the net they went into the complex type (Which I am familure with) such as crc16 crc32

    But this sounds great

    Thanks

  4. #4


    Did you find this post helpful? Yes | No

    Talking

    Hi Treitmey,

    Glad I could help.

    The XOR method works great for a master-slave system (don't say that in L.A. though).

    However, if you're working with micros in various locations that send data randomly without a master to control them, you will need to use a more complex scheme.

    Also, with the method I showed you, there is the small chance that you could miss an error. If electrical noise knocked a bit high on one character and then somewhere down the line knocked that same bit high on a different character, it could slip past this method. Fortunately, the chances of a coincidence like that are remote.

    I'm currently working on a slight variation of the XOR method that can be used with the XOR method. It will not allow what I described above to occurr.

    I'll keep you posted.

    It would be nice to get some input from the list on the XOR method. I know that losts of people use it. I think it's also called a "rolling checksum". I may be wrong though.

    picnaut
    ---> picnaut

Similar Threads

  1. Dallas CRC8 Routines
    By Tom Estes in forum Code Examples
    Replies: 23
    Last Post: - 8th May 2018, 18:07
  2. Checksum
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 24th October 2009, 04:09
  3. 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
  4. How to calculate CRC16 checksum for iButton
    By ashwini kotwal in forum General
    Replies: 13
    Last Post: - 17th March 2008, 19:48
  5. Dallas CRC16 Routines
    By Tom Estes in forum Code Examples
    Replies: 0
    Last Post: - 16th May 2005, 15:29

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