Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
crc8.cpp
00001 #include <inttypes.h> 00002 00003 #define CRC8INIT 0x00 00004 #define CRC8POLY 0x18 //0X18 = X^8+X^5+X^4+X^0 00005 00006 uint8_t crc8 ( uint8_t *data_in, uint16_t number_of_bytes_to_read ) 00007 { 00008 uint8_t crc; 00009 uint16_t loop_count; 00010 uint8_t bit_counter; 00011 uint8_t data; 00012 uint8_t feedback_bit; 00013 00014 crc = CRC8INIT; 00015 00016 for (loop_count = 0; loop_count != number_of_bytes_to_read; loop_count++) 00017 { 00018 data = data_in[loop_count]; 00019 00020 bit_counter = 8; 00021 do { 00022 feedback_bit = (crc ^ data) & 0x01; 00023 00024 if ( feedback_bit == 0x01 ) { 00025 crc = crc ^ CRC8POLY; 00026 } 00027 crc = (crc >> 1) & 0x7F; 00028 if ( feedback_bit == 0x01 ) { 00029 crc = crc | 0x80; 00030 } 00031 00032 data = data >> 1; 00033 bit_counter--; 00034 00035 } while (bit_counter > 0); 00036 } 00037 00038 return crc; 00039 }
Generated on Tue Jul 12 2022 18:13:34 by
1.7.2