Pages: [1]   Go Down
Author Topic: CRC byte assembly and disassembly  (Read 616 times)
0 Members and 1 Guest are viewing this topic.
Moss
Offline Offline
Full Member
***
Karma: 1
Posts: 119
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I have a stream of bytes with a final crc byte I would like to compare with to check for errors.

in visual basic, it is written like this:
Code:
crc=0
For i=o To (n_rx - 2)
  crc += rxbuf(i)
Next i
crc = crc And HFF
If crc = rxbuf(n_rx -1)Then

How would I translate this to arduinian?
Logged

Guildford, UK
Offline Offline
Full Member
***
Karma: 0
Posts: 217
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You've no supplied the VB code to declare the variables used so I'm assuming you can do this.

Code:
crc = 0;
for (i = o; i < n_rx - 2; i++)
{
  crc += rxbuf[i];
}

crc = crc & 0xff;
if (crc == rxbuf[n_rx - 1])
{
}
Logged

Moss
Offline Offline
Full Member
***
Karma: 1
Posts: 119
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks a lot
Logged

Pages: [1]   Go Up
Jump to: