Herunterladen Inhalt Inhalt Diese Seite drucken

Calcolo 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
Trasduttori di posizione AT Micropulse nel contenitore a profilo tondo
7
Lavorare con il metodo DPI/IP (cont.)
7.3

Calcolo CRC

Il CRC nel telegramma di richiesta
viene calcolato sulla base dei caratteri
CI e LEN. Nel telegramma di risposta il
calcolo CRC comprende i caratteri
CR, LEN e D0 ... Dn.
Implementazione del calcolo CRC nel linguaggio di programmazione 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;
}
Pseudocodice del calcolo 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)
Nota: NextBit è il bit successivo del flusso di bit seriale. I bit di avvio, di parità e
di stop non vengono inclusi nel calcolo CRC; vengono trattati in modo indipen-
dente dalla funzione UART. La funzione UART invia/riceve prima il LSB (least
significant bit), pertanto il CRC deve iniziare con 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
*/
*/
italiano
7 7

Werbung

Inhaltsverzeichnis
loading

Inhaltsverzeichnis