0
\$\begingroup\$

I have communication between an EEPROM and a microprocessor over SPI and I want to take care of data integrity.

Could you please confirm my below understanding?

I have a data which I want to write in the EEPROM along with a CRC code. Before writing in EEPROM I will use a CRC16 polynomial to generate a CRC code and append it to the data and send if over SPI to the EEPROM.

When I read the EEPROM after system reset or tun time again over SPI from the microcontroller the data along with the CRC code are read (data+crc) and it is divided by same CRC16 polynomial to check with remainder zero? If zero data is good else not.

Could you please confirm if my above understanding is correct?

I just have to implement data integrity for one memory block and for that I'm doing dual CRC check for single memory block by implementing redundant block.

\$\endgroup\$
  • 1
    \$\begingroup\$ with a checksum (adding up all the bytes) you can have the result be all zeros or all ones. With a CRC this is not expected, not normal. you run all but the crc bytes through the algorithm, and then compare with the crc bytes on the eeprom. \$\endgroup\$ – old_timer Aug 1 at 13:34
  • \$\begingroup\$ @old_timer Either that, or calculate the CRC of data+CRC and expect to have a constant check value, which can in most simple case be engineered to zero. It's been discussed below already. \$\endgroup\$ – Justme Aug 1 at 14:31
  • \$\begingroup\$ Well certainly not easily engineered to zero, that either requires a weak crc or a lot of fill bytes used to tune the final result. In general you dont want a weak CRC so in general how it works is you check the bytes, the exception would be to attempt for a fixed result no matter what the payload is. For a checksum then it is common to integrate the fill data to make a fixed result, more normal than exception. \$\endgroup\$ – old_timer Aug 1 at 15:48
3
\$\begingroup\$

The remainder will alwas be the same, but if it is always zero or something elsr depends on the exact CRC algorithm, namely the "final xor".

If you have to write for example written 10 bytes of data and have calculated 2 bytes of CRC from that data, you write 12 bytes to the memory.

When you read if back, you read all 12 bytes, calculate the CRC from the first 10 bytes, and check that the calculated CRC matches the 2 bytes of CRC read back from the memory.

There is also another method to calculate the CRC of all 12 bytes read back, it will add up to a constant check value if the CRC is correct, but depending on the CRC algorithm you use the result could be always zero but it can be something else too.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Thank you , concur with my understanding. \$\endgroup\$ – bluebear Aug 1 at 9:12
  • 1
    \$\begingroup\$ It will be zero, if the last word is CRC. CRC(Data+CRC)=0 \$\endgroup\$ – Marko Buršič Aug 1 at 9:30
  • \$\begingroup\$ @MarkoBuršič it will be zero, if the algorithm to calculate the CRC over CRC and data does not incude a final xor. Thus the check value might always be zero or some other constant that is non-zero, depending on which algorithm is used. \$\endgroup\$ – Justme Aug 1 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.