How to calculate CRC16 checksum for iButton


Closed Thread
Results 1 to 14 of 14
  1. #1

    Default How to calculate CRC16 checksum for iButton

    I have made small iButton project. I want to calculate CRC-16 checksum in which polynomial is x^16 + x^15 + x^2 + 1. If I use 'writePagePacket' function for writing data on iButton then it gets automatically calculated, how will I get CRC checksum using 'write' function only?

  2. #2


    Did you find this post helpful? Yes | No

    Default Crc16

    Hi there
    I am mot famiriar with the ibutton you work on but here are my code i use in a modbus protocol to calculate CRC16 cheksums

    Calcul_CRC16:

    CRC16=$FFFF
    For i=0 to (DataAmount -3)
    CRC16=CRC16^DATACRC[i]
    For j=1 to 8
    IF CRC16.Bit0=1 Then
    CRC16=$A001^(CRC16>>1)
    Else
    CRC16=CRC16>>1
    EndIF
    Next j
    Next i
    Return

    hope it helps

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    And if you change the

    Code:
    For j=1 to 8
    to

    Code:
    For j=0 to 7
    you will gain and a few memory bytes!

    Ioannis

  4. #4


    Did you find this post helpful? Yes | No

    Default

    i am not sure only one way to find out try and try again

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Dallas CRC16 Routines (Tom Estes)
    https://www.picbasic.co.uk/forum/showthread.php?t=1745

    I haven't used the CRC16 routines, but Tom's CRC8 worked great on a project of mine.
    <br>
    DT

  6. #6


    Did you find this post helpful? Yes | No

    Default Calculation of CRC 16 checksum

    Thanks for replying me.
    I tried the given code, but I am not able to write it in C#.Net. As I don't know the varaible type of CRC16. Can you please explain me?

  7. #7
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    Dear Andre

    i need the sample code for implementing modbus slave on a PIC16F877A

    please help me

  8. #8


    Did you find this post helpful? Yes | No

    Default

    here is the code i used on a 16f627
    Hope it helps
    Attached Files Attached Files

  9. #9
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    Dear Andre

    thank you for the code you have posted,actually i am trying to use the PIC16F877A

    another thing i have copy and pasted your code to proton+ compiler and i got some error messages one of them was
    for this part of the code:

    IF CRC16.Bit0=1 Then '<------ error here is saying Invalid Cast for this type of variable
    CRC16=$A001^(CRC16>>1)
    Else
    CRC16=CRC16>>1
    EndIF

    i don't know what does that means,please help me.

    Best Regards

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    First of all this is PBP forum list not Proton.

    Second, as this is PBP, all examples are for this compiler. The syntax is a little different.

    The syntax of the line IF CRC16.Bit0=1 Then means: Set bit 0 of the word variable CRC16.

    You have to open your manual and find how this can be accomplished in your Compiler.

    Ioannis

  11. #11
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    Daer Andre
    can you please post the circuit schematic for such code?

    i want to know what is the use for the
    PORTB.4 = 1
    PORTB.5 = 0

    any clue?

    best regards

  12. #12


    Did you find this post helpful? Yes | No

    Default

    Have you read the document emplementing modbus on serial comms,
    You can get it at www.modbus.org

  13. #13
    Join Date
    Feb 2008
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    Dear Andre

    yes i have the modbus specification.

    but these pins or at least PortB.5 is not something related to the specification,i think it is related to RS485 handshaking (correct me if i am wrong).

    is it correct?and which pin it is connected to?

  14. #14


    Did you find this post helpful? Yes | No

    Talking

    Sorry for the delay
    Yes pin portb.5 is for rs485 communication but this part is not working yet still need to try and find out why
    ps. any idea why it does not work
    Portb.4 is only showing running
    Hope this help

Similar Threads

  1. Checksum
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 24th October 2009, 04:09
  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. Dallas CRC16 Routines
    By Tom Estes in forum Code Examples
    Replies: 0
    Last Post: - 16th May 2005, 15:29
  4. Checksum problem!
    By atomski in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd November 2004, 07:21
  5. Checksum / CRC8 / CRC16
    By treitmey in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd December 2003, 14:40

Members who have read this thread : 0

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