I write a structure into EEPRM as follows
fract32 AmpF; // amplitude fundamental
fract32 AmpH; // amplitude harmonic
// mechanic angles and salt water angles of coil stored in coil-eeprom
// UINT32 gCoilSerialNumber;
// UINT32 gInversSerialNumber;
When you write the data to the EEPROM you calculate the value of the checksum and write it. When you read the data from the EEPROM, you calculate the checksum of this data and compare it with the checksum of the data you've just read, and if it does match it means (with a high probability) that your data is correct.
Basically if we represent your structure in memory :
byte |0 1 2 3|4 5 6 7|8 9 10 11|12 13|14 15| AmpF AmpH b d CRC
Then the 2-bytes CRC could be calculated like this :
CRC = (AmpF<<2) + (AmpF & 0x00FF) + (AmpH<<2) + (AmpH & 0x00FF) + (h<<2) + (h & 0x00FF) + d;
Which could obviously be optimized with a
for loop. I'm quite sure there are examples on the 'Net but an idea would be to go from the address of your structure to this address + sizeof(struct) - sizeof(CRC) by steps of 2 bytes.
Internet is full of implementations for checksums and CRCs that go from extremely simple to very complicated, depending on what you want to achieve and your system capabilities, but basically a simple checksum is just the addition of all the bytes in your data structure.
A simple checksum like the one I gave as an example only detects wrong bits in your data, you wouldn't detect if two values are swapped, e.g. AmpF and AmpH.
Note that though checksums and CRCs are a different thing, both terms are often used to designate the other.