PDA

View Full Version : How to calculate CRC16 checksum for iButton



ashwini kotwal
- 4th December 2007, 11:01
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?

Andre_Pretorius
- 6th December 2007, 19:40
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

Ioannis
- 6th December 2007, 20:18
And if you change the


For j=1 to 8

to


For j=0 to 7

you will gain and a few memory bytes!

Ioannis

Andre_Pretorius
- 7th December 2007, 05:22
i am not sure only one way to find out try and try again

Darrel Taylor
- 7th December 2007, 05:50
Dallas CRC16 Routines (Tom Estes)
1745

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

ashwini kotwal
- 10th December 2007, 05:08
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?

mech962784
- 13th February 2008, 21:32
Dear Andre

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

please help me

Andre_Pretorius
- 16th February 2008, 08:59
here is the code i used on a 16f627
Hope it helps

mech962784
- 16th February 2008, 10:33
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

Ioannis
- 16th February 2008, 12:33
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

mech962784
- 21st February 2008, 06:57
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

Andre_Pretorius
- 26th February 2008, 15:34
Have you read the document emplementing modbus on serial comms,
You can get it at www.modbus.org

mech962784
- 27th February 2008, 05:28
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?

Andre_Pretorius
- 17th March 2008, 19:48
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