Practice:
Here the table driven crc-8 we use. Not sure what the polynomial is.
First is the table:
const int8 crc8_Table[ ] =
{
0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65,
157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220,
35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98,
190, 224, 2, 92, 223, 129, 99, 61, 124, 34, 192, 158, 29, 67, 161, 255,
70, 24, 250, 164, 39, 121, 155, 197, 132, 218, 56, 102, 229, 187, 89, 7,
219, 133, 103, 57, 186, 228, 6, 88, 25, 71, 165, 251, 120, 38, 196, 154,
101, 59, 217, 135, 4, 90, 184, 230, 167, 249, 27, 69, 198, 152, 122, 36,
248, 166, 68, 26, 153, 199, 37, 123, 58, 100, 134, 216, 91, 5, 231, 185,
140, 210, 48, 110, 237, 179, 81, 15, 78, 16, 242, 172, 47, 113, 147, 205,
17, 79, 173, 243, 112, 46, 204, 146, 211, 141, 111, 49, 178, 236, 14, 80,
175, 241, 19, 77, 206, 144, 114, 44, 109, 51, 209, 143, 12, 82, 176, 238,
50, 108, 142, 208, 83, 13, 239, 177, 240, 174, 76, 18, 145, 207, 45, 115,
202, 148, 118, 40, 171, 245, 23, 73, 8, 86, 180, 234, 105, 55, 213, 139,
87, 9, 235, 181, 54, 104, 138, 212, 149, 203, 41, 119, 244, 170, 72, 22,
233, 183, 85, 11, 136, 214, 52, 106, 43, 117, 151, 201, 74, 20, 246, 168,
116, 42, 200, 150, 21, 75, 169, 247, 182, 232, 10, 84, 215, 137, 107, 53
} ;
To use the table:
crc = initial_Value ;
// The initial value is usually zero, but non-zero values are better.
// You can pick any byte you want, just be sure it's the same every time.
for ( each byte_Value in the message or file )
{
crc = crc8_Table[ crc ^ byte_Value ] ;
}
// Some CRC implementations xor the final value with some other value.
crc = crc ^ xor_Value
principio -> 101100011010001000000000
polinomio 0x0131 100110001
_________
XOR 001010010
101001001 ->eliminamos los ceros de la izquierda.y bajamos del principio dos cifras porque son dos ceros los eliminados
polinomio 100110001
_________
xor 001111000
111100000 ->eliminamos 2 ceros bajamos 2 siguienes cifras
polinomio 100110001
_________
xor 011010001
110100010 ->eliminamos 1 cero bajamos 1 cifra
polinomio 100110001
_________
xor 010010011
100100111 ->eliminamos 1 cero bajamos 1 cifra
polinomio 100110001
__________
xor 000010110
101100000 ->eliminamos 4 ceros bajamos 4 cifras
polinomio 100110001
_________
xor 001010001
101000100 ->eliminamos 2 ceros bajamos 2 cifras
polinomio 100110001
_________
xor 001110101
111010100 ->eliminamos 2 ceros bajamos 2 cifras
polinomio 100110001
_________
xor 011100101
111001010 ->eliminamos 1 cero bajamos 1 cifra
polinomio 100110001
_________
xor 011111011 resultado: 0xFB
esta operacion es para calcular el crc de dos bytes.pero no se como hacer para calcular una cadena mas larga.haber si lo veo.Byte 8 of the scratchpad is read-only and contains the CRC code for bytes 0 through 7 of the scratchpad....
CRC bytes are provided as part of the DS18B20’s 64-bit ROM code and in the 9th byte of the scratchpad...
memory. The ROM code CRC is calculated from the first 56 bits of the ROM code and is contained in the
most significant byte of the ROM. The scratchpad CRC is calculated from the data stored in the
scratchpad, and therefore it changes when the data in the scratchpad changes
This circuit consists of a shift register and XOR gates, and the
shift register bits are initialized to 0. Starting with the least significant bit of the ROM code or the least
significant bit of byte 0 in the scratchpad, one bit at a time should shifted into the shift register. After
shifting in the 56th bit from the ROM or the most significant bit of byte 7 from the scratchpad, the
polynomial generator will contain the re-calculated CRC. Next, the 8-bit ROM code or scratchpad CRC
from the DS18B20 must be shifted into the circuit.
0xB1 0xA2 0x00 <- valor inicial"0x00"
principio -> 101100011010001000000000
polinomio 0x0131 100110001
_________
XOR 001010010
101001001 ->eliminamos los ceros de la izquierda.y bajamos del principio dos cifras porque son dos ceros los eliminados
polinomio 100110001
_________
xor 001111000
111100000 ->eliminamos 2 ceros bajamos 2 siguienes cifras
polinomio 100110001
_________
xor 011010001
110100010 ->eliminamos 1 cero bajamos 1 cifra
polinomio 100110001
_________
xor 010010011
100100111 ->eliminamos 1 cero bajamos 1 cifra
polinomio 100110001
__________
xor 000010110
101100000 ->eliminamos 4 ceros bajamos 4 cifras
polinomio 100110001
_________
xor 001010001
101000100 ->eliminamos 2 ceros bajamos 2 cifras
polinomio 100110001
_________
xor 001110101
111010100 ->eliminamos 2 ceros bajamos 2 cifras
polinomio 100110001
_________
xor 011100101
111001010 ->eliminamos 1 cero bajamos 1 cifra
polinomio 100110001
_________
xor 011111011 resultado: 0xFB
vuelvo a realizar el calculo con 3 bytes: 0xb1 0xa2 0xa3 0x00
principio -> 10110001101000101010001100000000
poli 100110001
_________
00101001001
100110001
_________
00111100000
100110001
_________
0110100010
100110001
_________
0100100110
100110001
_________
0000101111010
100110001
_________
00100101110
100110001
_________
0000111110011
100110001
_________
0110000100
100110001
_________
0101101010
100110001
_________
00101101100
100110001
_________
00101110100
100110001
_________
00100010100
100110001
_________
000100101 = 0x25
asi que no me cuadra el valor final de crc.cuando en la pagina del enlace el resultado es 0xC7