cancel
Showing results for 
Search instead for 
Did you mean: 

Regarding of checksum code for an adc values to avoid spaces with value

RKUMA.2
Associate II

Hello,

I working on the stm32f070c6t6 , i want to transmit an adc value to the LabVIEW VISA and storing the adc values in the labview array further processing . but when i continously giving the command from the USB COM port for adc value sometimes it is showing some extra spaces along with after adc value and in the array sometimes the values are coming exactly some times not . so that i am using the checksum code for an adc value i.e uint16_t adc_result =... and I am moving this value into uint8_t data[50] array using sprintf and transmitting the array through usb transmit function but some times the values are correct some times its coming along with spaces (note: every time i am clearing the array [50] using memset function), in order to avoid the spaces i use a checksum code of (from stm32 community group memeber suggestion )

uint16_t result =...;

uint8_t checksum=result >>8 +result;

if (checksum!= (uint8_t )(result>>8+result)){

printf("error while transmitting the data");

//stop usb transmitting function

}

this code also sometimes works properly sometimes not, how can i avoid spaces along with values please if you have an idea give a suggestion.can you please provide the defined c code for checksum.

Best regards

raj

1 REPLY 1
Piranha
Chief II

There is no need for a checksum "to avoid spaces". And that checksum code has a simple but fatal bug, which I described it your original topic:

https://community.st.com/s/question/0D53W000012PyiiSAC/how-to-checksum-the-adc-data-when-it-is-passing-to-serial-monitor-of-putty-through-the-usb-virtual-com-port

Your code shows only one thing - the chosen task is way over your current skill level. Beginners cannot build a space ship, one has to start with the basics. Isn't it obvious? You wanted suggestions... Here they are:

  1. Learn splitting your thoughts into sentences.
  2. Learn the basic C programming.
  3. Study the existing protocols, for example MODBUS.