Herunterladen Inhalt Inhalt Diese Seite drucken

Crc Check - Balluff BTL6-P111-M-A1-S115 series Datenblatt Und Anleitung

Inhaltsverzeichnis

Werbung

Verfügbare Sprachen
  • DE

Verfügbare Sprachen

  • DEUTSCH, seite 1
BTL6-P111-M_ _ _ _-A1-S115
Micropulse AT Transducer in round profile housing
7
Using DPI/IP Procedure (cont.
7.3

CRC check

The CRC in the reply telegram is
checked using the characters CI
and LEN. In the response telegram,
the CRC check includes the charac-
ters CR, LEN and D0 ... Dn.
Implementation of the CRC check in C programming language:
typedef unsigned char byte;
typedef unsigned short word;
#define GENERATOR_POLINOM
#define CRC_OK
0
#define CRC_BAD 1
#define BUFFSIZE
byte bRxBuffer[BUFFSIZE];
byte bMessageLength;
int
CRCCalculation(void)
(
word wCRC;
byte bNextByte;
int
i, j;
wCRC = 0;
for ( i = 0; i < bMessageLength - 2; i++ ) {/* do not calculate on CRC bytes */
bNextByte = bRxBuffer[i];
for ( j = 0; j < 8; J++ ) {
if ( ( bNextByte & 0x01) ^ ((wCRC & 0x800) >> 15) ) {
}
else {
}
bNextByte >>= 1;
}
}
if ( (byte) ((wCRC & 0xff00) >> 8) == bRxBuffer[i] &&
(byte) (wCRC & 0x00ff) == bRxBuffer[i+1] ) {
return CRC_OK;
}
else return CRCBAD;
}
Pseudo-Code for the CRC check:
CRC = 0;
repeat
CRCNext = NextBit EXOR CRC(15);
CRC(15:1) = CRC(14:0);
CRC(0) = 0;
if CRCNext then
endif
until (last data bit)
Note: NextBit is the next bit of the serial bit stream. The Start, parity and
Stop bits are not included in the CRC check; they are treated independently
by the UART function. The UART function sends/receives the LSB first, so the
CRC must begin with Bit 0.
0x01021
48
/* received message, 1
/* number of characters in received message */
/* including CRC
wCRC <<= 1;
wCRC ^= GENERATOR_POLINOM;
wCRC <<= 1;
// initialize shift register
CRC(14:0) = CRC(14:0) EXOR 0x1021;
st
byte @ index 0
*/
// shift left by 1
*/
english
7 7

Werbung

Inhaltsverzeichnis
loading

Inhaltsverzeichnis