Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

CRC32 mismatch in PHP and microcontroller

Status
Not open for further replies.

akshada

Member level 3
Member level 3
Joined
Jun 29, 2010
Messages
67
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
india
Activity points
1,746
hello all,
i am trying to calculate crc32 of a binary file in chunks of 500 bytes. I'll give you a general idea what my system is doing.
I am trying to send the binary packets from server to my controller and i've written a crc32 code in php and the same crc32 algorithm is being implemented in microcontroller(STM32F100xx) for first few 500 bytes, it gives correct result but later on it is mismatched
PHP crc32 gives: 331516C0
microcontroller CRC32 : 331516C

the controller is not showing the last 0.
for your reference i am pasting my crc32 algorithm

Code:
uint32_t crc32_gen(unsigned char *block, unsigned int bytelength)
{
   register unsigned long crc;
   unsigned long i;

   crc = 0xFFFFFFFF;
   for (i = 0; i < bytelength; i++)
   {
	     crc = ( (crc >> 8) & 0x00FFFFFF ) ^ crc32_tab[(crc & 0xFF) ^ *block++ ];

   }
   return (crc ^ 0xFFFFFFFF);
}

PHP crc32:
Code:
function crc32gen(&$buffer,$bytelength)
{
   
   $crc_table = $GLOBALS['crc_table'];
   $crc = 0xFFFFFFFF;                          
   for($i=0;$i < $bytelength;$i++)
   {
     
	   $crc = (($crc >> 8) & 0x00FFFFFF) ^ $crc_table [($crc & 0xFF) ^ ord($buffer[$i])];
	
   }
   return($crc ^ 0xFFFFFFFF);
}

thanks for your suggestion
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top