CRC calculation in Modbus
Jan 6, 2005 9:54 pm, by Max Power
This seems pretty straightforward. I typed it all in from memory, so if there are bugs, let me
know.
Max
superalpha@yahoo.com
-------------------------------------------------
unsigned int CRC16;
#define SEED 0xFFFF //initialization for CRC16
#define GP 0xA001 //generating polynomial
//for standard CRC16
//(remainder of division)
//to start a new CRC, set CRC16 = SEED
//then for each byte call Calc_CRC(byte, &CRC16);
//CRC16 will contain the result
//(if you calculate all of the incoming data
//INCLUDING the CRC, the result should be 0x0000
//and if you are sending the CRC be sure to
//send the bytes in the correct order)
void Calc_CRC(unsigned byte b, unsigned int* CRC)
{
BOOL carry;
int i;
CRC[0] ^= b & 0xFF;
for (i=0; i<8; i++)
{
carry = CRC[0] & 0x0001;
CRC[0]>>=1;
if (carry) CRC[0] ^= GP;
}
}
-------------------------------------------------
Reply
Re: CRC calculation in Modbus
Jan 6, 2005 4:03 pm, by Andrzej
Hi
On http://www.modbus.pl you can find the CRC function in C and more about modbus
protocol.
Regards
Andrzej
Reply
Re: CRC calculation in Modbus
Jan 6, 2005 2:15 pm, by Bernd Bauer
Yes, I realized two years ago a Modbus communication including the CRC-16 Checksum
calculation on a Honeywell IPC620 PLC.
The source for calculation I've found somewhere as C Code. I don´t remember from what
website, but I have it still printed on paper. If You send me a fax number I can send You a
copy.
With kind regards
Bernd Bauer
bbauerberk@aol.com
Reply
Re: CRC calculation in Modbus
Jan 6, 2005 2:08 pm, by Tibor
http://www.modicon.com/techpubs/crc7.html#0.2..637OJU.KDG87D.4
Reply
Re: CRC calculation in Modbus
Jan 6, 2005 2:05 pm, by Evandro Vizicato
Dear Ralf
I have a PDF file of Modbus Master Protocol.
send me your e-mail that i send the document for you.
Evandro Vizicato
evandro.vizicato@uol.com.br
Reply
Re: CRC calculation in Modbus
Jan 6, 2005 1:46 pm, by Andrzej
Hi
Go to http://www.modbus.pl
Regards
Andrzej
Reply
RE: CRC calculation in Modbus
Jan 4, 2005 2:09 pm, by Eddie Hague - FieldServer
You will find CRC calculation examples in the free Modbus RTU source code at the
ProtoCessor website:
http://www.protocessor.com/techsupport/Free_Modbus_RTU_Source_Code.asp
Eddie Hague, CTO
FieldServer Technologies
Reply
Re: CRC calculation in Modbus
Jan 7, 2005 6:47 pm, by Mark Jones
Page 112 of PI_MBUS_300_J.
Reply