This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Dallas Ibutton CRC check in C or C

Does anyone have developed the code to check the CRC of an ibutton connected via one-wire to a quadi-directional port ?

I'm studing how to develop it, there's someone who want speak about ?

Parents
  • I've created my own function for the ibutton CRC, because i didn't like those of dallas.
    Its simpler, and easy to understand. The data from the ibutton is stored on a[i] vec (i from 0 to 6).
    a[0] is the Family Code
    a[1] is the first ID byte, and so on.
    The function returns the CRC byte.

    Code:

    int a[8];

    int crc_check()
    { int crc_byte; int byte_counter; int bit_counter;

    crc_byte=0;

    for(byte_counter=0; byte_counter < 8; byte_counter++) { for(bit_counter=0; bit_counter < 8; bit_counter++) { if(!bit_test(a[byte_counter],0) && !bit_test(crc_byte,0)) { a[byte_counter] >>= 1; crc_byte >>= 1; continue; } if(bit_test(a[byte_counter],0) && bit_test(crc_byte,0)) { a[byte_counter] >>= 1; crc_byte >>= 1; continue; } a[byte_counter] >>= 1; crc_byte >>= 1; crc_byte = crc_byte ^ 0b10001100; } }

    return crc_byte;
    }

Reply
  • I've created my own function for the ibutton CRC, because i didn't like those of dallas.
    Its simpler, and easy to understand. The data from the ibutton is stored on a[i] vec (i from 0 to 6).
    a[0] is the Family Code
    a[1] is the first ID byte, and so on.
    The function returns the CRC byte.

    Code:

    int a[8];

    int crc_check()
    { int crc_byte; int byte_counter; int bit_counter;

    crc_byte=0;

    for(byte_counter=0; byte_counter < 8; byte_counter++) { for(bit_counter=0; bit_counter < 8; bit_counter++) { if(!bit_test(a[byte_counter],0) && !bit_test(crc_byte,0)) { a[byte_counter] >>= 1; crc_byte >>= 1; continue; } if(bit_test(a[byte_counter],0) && bit_test(crc_byte,0)) { a[byte_counter] >>= 1; crc_byte >>= 1; continue; } a[byte_counter] >>= 1; crc_byte >>= 1; crc_byte = crc_byte ^ 0b10001100; } }

    return crc_byte;
    }

Children