onewire:crc
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| onewire:crc [2012/05/15 15:40] – fdc | onewire:crc [2013/09/18 09:08] (current) – sdolt | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| < | < | ||
| + | |||
| + | < | ||
| ====== DOW CRC (Dallas One Wire CRC) ====== | ====== DOW CRC (Dallas One Wire CRC) ====== | ||
| + | <note warning> | ||
| ===== DOW CRC-8 ===== | ===== DOW CRC-8 ===== | ||
| Line 37: | Line 40: | ||
| </ | </ | ||
| ==== Exemple de fonctionnement ==== | ==== Exemple de fonctionnement ==== | ||
| - | 1-Wire ROM: A2 00 00 00 01 B8 1C 02 \\ CRCPOLY8 = 0x18 | + | 1-Wire ROM: A2 00 00 00 01 B8 1C 02 \\ CRCPOLY8 = 0x18 \\ CRCinitial = 0x00 |
| === i=0 === | === i=0 === | ||
| === b = string [15] <=> ' | === b = string [15] <=> ' | ||
| Line 407: | Line 410: | ||
| === i=2 === | === i=2 === | ||
| === b = string [13] <=> ' | === b = string [13] <=> ' | ||
| + | |||
| + | . \\ . \\ . | ||
| + | |||
| + | === i=13 === | ||
| + | === b = string [2] <=> ' | ||
| + | |||
| + | . \\ . \\ . | ||
| + | |||
| + | == bit_counter = 1 == | ||
| + | |||
| + | <code c> feedback_bit = (crc ^ b) & 0x01;</ | ||
| + | ^ crc XOR b ^^ | ||
| + | | crc | 0101' | ||
| + | | b | 0000' | ||
| + | ^ Résultat | 0101' | ||
| + | |||
| + | ^ (crc XOR b) & 0x01 ^^ | ||
| + | |crc XOR b | 0101' | ||
| + | | 0x01 | 0000' | ||
| + | ^ Résultat | ||
| + | |||
| + | **=> feedback_bit = 0x01** | ||
| + | |||
| + | <code c> if (feedback_bit == 0x01) crc = crc ^ CRCPOLY8; </ | ||
| + | |||
| + | ^ crc XOR CRCPOLY8 | ||
| + | | crc | 0101' | ||
| + | | CRCPOLY8 | ||
| + | ^ Résultat | ||
| + | |||
| + | **=> crc = 0x45** | ||
| + | |||
| + | <code c> crc = (crc >> 1) & 0x7F; </ | ||
| + | |||
| + | ^ crc>> | ||
| + | | crc | 0100' | ||
| + | ^ crc>> | ||
| + | |||
| + | ^ (crc>> | ||
| + | | crc>> | ||
| + | | 0x7F | 0111' | ||
| + | ^ Résultat | ||
| + | |||
| + | **=> crc = 0x22** | ||
| + | |||
| + | <code c> if (feedback_bit == 0x01) crc = crc | 0x80; </ | ||
| + | |||
| + | ^ crc OR 0x80 ^^ | ||
| + | | crc | 0010' | ||
| + | | 0x80 | 1000' | ||
| + | ^ Résultat | ||
| + | |||
| + | **=> crc = 0xA2 {C'est la valeur du CRC pour [00000001B81C (Numéro de série) + 02 (Family Code)], s'il est ajouté à la suite du numéro de série, le CRC final sera de 0x00!}** | ||
| + | |||
| + | . \\ . \\ . | ||
| + | |||
| + | === i=14 === | ||
| + | === b = string [1] <=> ' | ||
| . \\ . \\ . | . \\ . \\ . | ||
| Line 419: | Line 480: | ||
| . \\ . \\ . | . \\ . \\ . | ||
| - | **=> crc = 0x00** | + | **=> crc = 0x00 {Nous avons au final un 0x00, 0xA2 est bel et bien le CRC de [00000001B81C02]}** |
| ===== DOW CRC-16 ===== | ===== DOW CRC-16 ===== | ||
| Line 428: | Line 489: | ||
| #include < | #include < | ||
| #include < | #include < | ||
| - | #define CRCPOLY16 0x4002 | + | #define CRCPOLY16 0x4002 |
| void main(void) | void main(void) | ||
| Line 455: | Line 516: | ||
| ==== Exemple de fonctionnement ==== | ==== Exemple de fonctionnement ==== | ||
| - | 1-Wire ROM: 75 \\ CRCPOLY8 | + | 1-Wire ROM: 75 \\ CRCPOLY16 |
| === i=0 === | === i=0 === | ||
| === b = string [1] <=> ' | === b = string [1] <=> ' | ||
onewire/crc.1337096408.txt.gz · Last modified: 2012/05/15 15:40 by fdc