Herunterladen Inhalt Inhalt Diese Seite drucken

Calcul Du Crc - 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
Capteur de déplacement Micropulse AT en boîtier rond profilé
7
Utilisation du procédé DPI/IP (suite)
7.3

Calcul du CRC

Le CRC du datagramme d'interroga-
tion se calcule à partir des caractères
CI et LEN. Dans le datagramme de
réponse, le calcul du CRC se calcule
à partir des caractères CR, LEN
et D0 ... Dn.
Implémentation du calcul CRC en langage C :
typedef unsigned char byte;
typedef unsigned short word;
#define GENERATOR_POLINOM 0x01021
#define CRC_OK
0
#define CRC_BAD 1
#define BUFFSIZE
byte bRxBuffer[BUFFSIZE]; /* received message, 1
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 du calcul du CRC :
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 est le bit suivant de la séquence binaire. Les bits start, parity et
stop ne sont pas inclus au calcul ; ils sont traités indépendamment par la fonc-
tion UART. La fonction UART émet et reçoit d'abord le bit de plus faible poids
(LSB), le calcul CRC doit donc commencer par le bit 0.
48
/* 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
*/
*/
français
7 7

Werbung

Inhaltsverzeichnis
loading

Inhaltsverzeichnis