User Tools

Site Tools


onewire:crc

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
onewire:crc [2012/05/15 15:39] fdconewire:crc [2013/09/18 09:08] sdolt
Line 1: Line 1:
-<note>Les exemples pratiques utilisés dans cette démonstration proviennent de [[http://www.maxim-ic.com/app-notes/index.mvp/id/27|cette page]]. </note>+<note>Les exemples pratiques utilisés dans cette démonstration proviennent de [[http://www.maxim-ic.com/app-notes/index.mvp/id/27|cette page]]. </note 
 + 
 +<note>Sur processeur AVR, une bibliothèque existe : [[avr:crc16.h|Somme de contrôle CRC]]</note>
  
 ====== DOW CRC (Dallas One Wire CRC) ====== ====== DOW CRC (Dallas One Wire CRC) ======
 +<note warning>Le code ci-dessous ne fonctionne pas. Mélange entre chaine de caractère et chaine normale</note>
  
 ===== DOW CRC-8 ===== ===== DOW CRC-8 =====
Line 32: Line 35:
                 }                 }
         }         }
-        printf("%#x\n,crc);+        printf("%#x\n",crc);
 } }
  
 </file> </file>
 ==== 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] <=> '2' [0000'0010] === === b = string [15] <=> '2' [0000'0010] ===
Line 407: Line 410:
 === i=2 === === i=2 ===
 === b = string [13] <=> 'C' [0000'1100] === === b = string [13] <=> 'C' [0000'1100] ===
 +
 +. \\ . \\ .
 +
 +=== i=13 ===
 +=== b = string [2] <=> '0' [0000'0000] ===
 +
 +. \\ . \\ .
 +
 +== bit_counter = 1 ==
 +
 +<code c> feedback_bit = (crc ^ b) & 0x01;</code>
 +^  crc XOR b  ^^
 +|  crc  |  0101'1101  |
 +|  b  |  0000'0000  |
 +^ Résultat |  0101'1101  |
 +
 +^  (crc XOR b) & 0x01  ^^
 +|crc XOR b  |  0101'1101  |
 +|  0x01  |  0000'0001  |
 +^  Résultat  |  0000'0001  |
 +
 +**=> feedback_bit = 0x01**
 +
 +<code c> if (feedback_bit == 0x01) crc = crc ^ CRCPOLY8; </code>
 +
 +^  crc XOR CRCPOLY8  ^^
 +|  crc  |  0101'1101  |
 +|  CRCPOLY8  |  0001'1000  |
 +^  Résultat  |  0100'0101  |
 +
 +**=> crc = 0x45**
 +
 +<code c> crc = (crc >> 1) & 0x7F; </code>
 +
 +^  crc>> ^^
 +|  crc  |  0100'0101  |
 +^  crc>> |  0010'0010  |
 +
 +^  (crc>>1) & 0x7F  ^^
 +|  crc>> |  0010'0010  |
 +|  0x7F  |  0111'1111  |
 +^ Résultat  |  0010'0010  |
 +
 +**=> crc = 0x22**
 +
 +<code c> if (feedback_bit == 0x01) crc = crc | 0x80; </code>
 +
 +^  crc OR 0x80  ^^
 +|  crc  |  0010'0010  |
 +|  0x80  |  1000'0000  |
 +^  Résultat  |  1010'0010  |
 +
 +**=> 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] <=> '2' [0000'0010] ===
  
 . \\ . \\ . . \\ . \\ .
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 <stdio.h> #include <stdio.h>
 #include <string.h> #include <string.h>
-#define CRCPOLY16 0x4002           //correspond au masque des XOR sur le polynôme x^16+x^15+x^2+x+#define CRCPOLY16 0x4002           //correspond au masque des XOR sur le polynôme x^16+x^15+x^2+x^0
  
 void main(void) void main(void)
Line 455: Line 516:
  
 ==== Exemple de fonctionnement ==== ==== Exemple de fonctionnement ====
-1-Wire ROM: 75 \\ CRCPOLY8 = 0x4002 \\ CRCinitial = 0x90F1+1-Wire ROM: 75 \\ CRCPOLY16 = 0x4002 \\ CRCinitial = 0x90F1
 === i=0 === === i=0 ===
 === b = string [1] <=> '5' [0000'0000'0000'0101] === === b = string [1] <=> '5' [0000'0000'0000'0101] ===
onewire/crc.txt · Last modified: 2013/09/18 09:08 by sdolt