cancel
Showing results for 
Search instead for 
Did you mean: 

calculating checksum of struct

VYoun
Associate III

Hello,

I need to calculate checksum over a struct I have defined. Can anyone please help me with this?

The data is structured as below:

typedef struct eeprom_struct {
 
//	char serial_number[5];
	float detector_comp_ch0;
	float detector_comp_ch1;
	float detector_comp_ch2;
	float detector_comp_ch3;
	float detector_comp_ch4;
	float detector_comp_ch5;
	float detector_comp_ch6;
	float detector_comp_ch7;
	char serial_number[14];
	uint checksum;
 
 
} eeprom_struct;
 

I know this is not directly related to STM32 MCUs, but I really need to solve this, and could not get an answer anywhere else.

Thank you in advance for your help.

Best regards,

Vouria

10 REPLIES 10

This all seems like mundane C coding,

uint sum32(int size, uint8_t *ptr)

{

uint sum = 0;

while(size--) sum += *ptr++; // sum bytes over buffer

return(sum);

}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..