첫 커밋. 시간이 없어서 정리 안함.

This commit is contained in:
2025-09-29 18:50:31 +09:00
commit cf0ecc4bd1
112 changed files with 103705 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
6.3.1 Example CRC calculation (C)
Below is a sample 1-byte CRC calculation in C language:
uint8_t calculate_i2c_crc(uint8_t last_crc, uint8_t new_data)
{
crc_result = 0;
// Extract bits of last_crc
for(i=0;i<8;i++)
{
crc_c[i] = (last_crc >> i) & 1;
}
// Extract bits of new_data
for(i=0;i<8;i++)
{
crc_d[i] = (new_data >> i) & 1;
}
crc_newcrc[7] = crc_d[7]^crc_d[6]^crc_d[5]^crc_c[5]^crc_c[6]^crc_c[7];
crc_newcrc[6] = crc_d[6]^crc_d[5]^crc_d[4]^crc_c[4]^crc_c[5]^crc_c[6];
crc_newcrc[5] = crc_d[5]^crc_d[4]^crc_d[3]^crc_c[3]^crc_c[4]^crc_c[5];
crc_newcrc[4] = crc_d[4]^crc_d[3]^crc_d[2]^crc_c[2]^crc_c[3]^crc_c[4];
crc_newcrc[3] =
crc_d[7]^crc_d[3]^crc_d[2]^crc_d[1]^crc_c[1]^crc_c[2]^crc_c[3]^crc_c[7];
crc_newcrc[2] =
crc_d[6]^crc_d[2]^crc_d[1]^crc_d[0]^crc_c[0]^crc_c[1]^crc_c[2]^crc_c[6];
crc_newcrc[1] = crc_d[6]^crc_d[1]^crc_d[0]^crc_c[0]^crc_c[1]^crc_c[6];
crc_newcrc[0] = crc_d[7]^crc_d[6]^crc_d[0]^crc_c[0]^crc_c[6]^crc_c[7];
// restore bits back to unsigned short
for(i=0;i<8;i++)
{
crc_result |= crc_newcrc[i] << i;
}
return crc_result;
}