you would need data +=2 before the loop to skip over the checksum field
Yikes! You are right!
I had meant to do an array summing using i as an index when I started, that is one reason I have the i variable.
But then I used the pointer instead and you are right, it sums in the checksum and leaves out the final part of the string.
I still have problems though (even after changing it the way you propose)...
It seems like the sizeof() function does not return the correct length of the struct. When I count up the variables contained in it, I get 47, but sizeof() returns 48!
So it looks like somehow I am getting a bogus byte added into my checksum and it throws off everything.
To try and fix this I changed member "Highcurrentmode" from unsigned char to unsigned int (8 bits to 16 bits). This did not change the size reported by sizeof(). Still size = 48.
When I store the struct in EEPROM I do it using a block write function that takes the address of the struct and the length (sizeof()). It should write the struct data including the checksum to EEPROM.
Then when I read back I use a similar block read function also using the address of the struct and sizeof() as length.
When I look at the actual data saved and retrieved they all look perfectly OK including
the checksum value written to EEPROM.
But still the checksum read back from EEPROM does not compare to what I calculate
(using the exact same function) across the read back
So I have good data as far as I can see but the checksum written into the struct at save time does not correspond to what I calculate at read time.
Must be some bug in the checksumming function, but it beats me what.
Currently it looks like this:
UINT CheckSumConf(void *cnf)
unsigned char *data;
data = cnf;
data += 2; //To get pointer past checksum;
for (i=2; i < sizeof(EEPROM); i++) chk += *data++;