cancel
Showing results for 
Search instead for 
Did you mean: 

how to checksum the ADC data when it is passing to serial monitor of putty through the USB virtual COM port.

RKUMA.2
Associate II

Hello ,

I am working on the stm32f070c6 controller , i am reading the adc values from controller and passing to the serial monitor of USB virtual COM port, but i want to checksum the values before transmitting the adc values to the serial monitor .how can i do it, if somebody have any idea please give me suggestion to how to checksum the adc values (theory wise I am sure).

Best regards

raj

1 ACCEPTED SOLUTION

Accepted Solutions

If your value is uint16_t adc_result, then a checksum could be:

uint16_t adc_result = ...;
uint8_t checksum = adc_result >> 8 + adc_result;

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

6 REPLIES 6
TDK
Guru

Are you asking how to calculate a checksum? Just add the bytes values together, transmit the result along with the original data, and verify it matches on the receiving end. Could also use a CRC to do this which is more complicated but has other advantages.

If you feel a post has answered your question, please click "Accept as Solution".

Thanks for your reply @TDK​ , theory wise I am sure, but in coding how can add the adc values while transmitting, the adc directly giving an adc in decimal form how can write code for checksum while transmitting I am little bit confused can you please clarify me in the coding part.

Thanks in Advance

raj

If your value is uint16_t adc_result, then a checksum could be:

uint16_t adc_result = ...;
uint8_t checksum = adc_result >> 8 + adc_result;

If you feel a post has answered your question, please click "Accept as Solution".

Thanks for your reply @TDK​ , when transmitting we will send adding of both values(rightshifted value along with adc value) ,at receiver side how can I check ? whether the data is proper or not.

How can you check? By writing code that does the check, of course.

if (checksum != (uint8_t) (adc_result >> 8 + adc_result)) {
    ...
}

If you feel a post has answered your question, please click "Accept as Solution".

The checksum code is wrong because the addition operator has a higher precedence than a shift operator.

https://en.cppreference.com/w/c/language/operator_precedence