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 ?
I suggest you study the Dallas Documentation - it includes a ready-made implementation!
See: www.8052.com/.../read.phtml
i tried that but it doesnt work so i think i can get a better one
Now why do you think the Dallas implementation doesn't work? Since Dallas created the protocol and specified the algorithm to use, they should be the source of information, shouldn't they?
What have you done, and what was the result? If you did something wrong you may switch to a houndred different solutions and still manage to do the same error...
i tried that but it doesnt work ... most likely you have a (hardware?) error that makes the CRC say 'wrong'.
so i think i can get a better one would that be one that did not detect the CRC error?
Have you - this is required - verified 1) that the CRC routine pick the right bytes in memory? 2) that these bytes will result in the same result as the Dallas routine 3) for test here is a Dallas ID string with good CRC (in hex) 01 fa 52 58 10 00 00 10
Erik
Note that there are (at least) two different CRCs used with iButtons and other 1-Wire (TM) devices:
There's the 8-bit CRC in the Serial Number;
Some devices also use a 16-bit CRC with their data "payload"...
See the sepcific device Datasheet for details.
No it works fine. I used it, along with most of their code.
Seconded.
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; }
Its simpler, and easy to understand Maybe it is simpler, but impossible to understand
The code fragment, as you posted it, is reminiscent of a Jackson Pollock ;)
way-off-topic: Who would have thought you could actually learn something about modern art in an embedded forum :-) Not that embedded development is not a modern art... :-)