Skip to main content
RKUMA.2
Associate III
Aug 30, 2021 5:11 AM UTC
Solved

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

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

This topic has been closed for replies.
TDK
TDKBest answer
Aug 30, 2021 8:33 AM UTC

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""."

6 replies

TDK
Aug 30, 2021 7:35 AM UTC

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""."
RKUMA.2
RKUMA.2Author
Associate III
Aug 30, 2021 8:29 AM UTC

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

TDK
TDKBest answer
Aug 30, 2021 8:33 AM UTC

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""."