Question
How can I calculate the CRC in java ?
Posted on July 04, 2013 at 04:30
Hello All,
I have a stm32f4 discovery. I'm sending out messages the first part is my ''header'' the rest is ''data'' then the tail is the crc value from the hw perph. This is the code I use to send the messages.// new data is coming in to this node from another
// broadcast handle it based on where it came from
// and what this node does with raw data
case
CMD_NEWDATA:
// send header
crcVal.UI32 = CRC_CalcBlockCRC((u32*)&Msg, 1);
sendRawData((u32*)&Msg, 1);
// send vardata
// todo if ptr type send that out dma etc
for
(i=0; i<Msg.size; i++)
{
crcVal.UI32 = CRC_CalcBlockCRC((u32*)&Msg.vd[i], 1);
sendRawData((u32*)&Msg.vd[i], 1);
}
// send out crc
sendRawData(&crcVal.UI32, 1);
CRC_ResetDR();
// reset the crc
break
;
this is what I see come out the other end
02 07 02 00 18 8A D0 23 25 2B 09 00 [[98 E2 D7 AC]]
02 07 02 00 7C 8A D0 23 25 2B 09 00 [[EA 63 8C 89]]
02 07 02 00 E0 8A D0 23 25 2B 09 00 [[DF EF D7 66]]
02 07 02 00 44 8B D0 23 25 2B 09 00 [[37 66 FA 53]]
02 07 02 00 A8 8B D0 23 25 2B 09 00 [[FF E6 DC 3A]]
02 07 02 00 0C 8C D0 23 25 2B 09 00 [[07 40 01 55]]
the part in the [[xx]] is the CRC My crc produced by java is nothing close to the crc produced by the stm. So now I'm kinda in a chicken/egg situation.
Question 1: is my crc even correct for the data preceding it ?
Question 2: (if question 1 is yes) how do I calculate the same crc in Java.
This is my Java code btw, just the part where it adds the last bit of crc
is.read(crcBytes, 0, 4);
crc.update(crcBytes);
if
(crc.getValue() == 0)
{
as always thanks for the time !