avr:crc16.h
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionLast revisionBoth sides next revision | ||
avr:crc16.h [2013/09/18 08:23] – created sdolt | avr:crc16.h [2013/09/18 09:05] – sdolt | ||
---|---|---|---|
Line 5: | Line 5: | ||
===== Utilisation sur microprocesseur AVR ===== | ===== Utilisation sur microprocesseur AVR ===== | ||
- | La bibliothèque standard avr-libc possède des fonctions permettant de calculer rapidement certain type de CRC grâce au fichier d' | + | La bibliothèque standard avr-libc possède des fonctions permettant de calculer rapidement certain type de CRC grâce au fichier d' |
<code c> | <code c> | ||
#include < | #include < | ||
</ | </ | ||
+ | Documentation : [[http:// | ||
+ | |||
+ | ==== CRC pour OneWire ==== | ||
+ | |||
+ | Le protocole OneWire utilise deux types de CRC, un sur 8 bits et l' | ||
+ | |||
+ | === DOW CRC8 === | ||
+ | Le CRC 8 bits est utilisés pour la lecture de la mémoire ROM. C'est mémoire de 8 octets contients 1 octets avec la famille du composant utilisé, 6 octets contenant un numéro de série unique et enfin un octets contenants le CRC des 7 octets précédents. | ||
+ | |||
+ | ^Famille^ID^CRC^ | ||
+ | |1 octet|6 octets| 1 octet| | ||
+ | |||
+ | Pour ce cas, on peut utilisé la fonction _crc_ibutton_update dans le prototype est : | ||
+ | <code c> | ||
+ | static __inline__ uint8_t _crc_ibutton_update (uint8_t __crc, uint8_t __data); | ||
+ | </ | ||
+ | === DOW CRC16 === | ||
+ | Le CRC 16 bits est utilisés pour la lecture et l' | ||
+ | |||
+ | Pour ce cas, on peut utilisé la fonction _crc16_update dans le prototype est : | ||
+ | <code c> | ||
+ | static __inline__ uint16_t _crc16_update (uint16_t __crc, uint8_t __data); | ||
+ | </ | ||
+ | |||
+ | === Exemple d' | ||
+ | Les exemples ci-dessous sont tirés de la documentation d' | ||
+ | == Calcul du CRC == | ||
+ | <code c> | ||
+ | // Contenu des 7 premiers octets de la mémoire ROM, donc sans l' | ||
+ | uint8_t serno[] = { 0x02, 0x1c, 0xb8, 0x01, 0, 0, 0 }; | ||
+ | |||
+ | uint8_t make_crc8(void) | ||
+ | { | ||
+ | uint8_t crc = 0 | ||
+ | uint8_t i; | ||
+ | |||
+ | for (i = 0; i < sizeof serno / sizeof serno[0]; i++) | ||
+ | crc = _crc_ibutton_update(crc, | ||
+ | |||
+ | return crc; // Return 0xa2 | ||
+ | } | ||
+ | </ | ||
+ | == Vérification du CRC == | ||
+ | <code c> | ||
+ | // Contenu des 8 octets de la mémoire ROM, donc avec l' | ||
+ | uint8_t serno[] = { 0x02, 0x1c, 0xb8, 0x01, 0, 0, 0, 0xa2 }; | ||
+ | |||
+ | uint8_t check_crc8(void) | ||
+ | { | ||
+ | uint8_t crc = 0 | ||
+ | uint8_t i; | ||
+ | |||
+ | for (i = 0; i < sizeof serno / sizeof serno[0]; i++) | ||
+ | crc = _crc_ibutton_update(crc, | ||
+ | |||
+ | return crc; // Return 0 is CRC is correct | ||
+ | } | ||
+ | </ |
avr/crc16.h.txt · Last modified: 2013/09/18 09:10 by sdolt