Hi there,
I have run into my first real problem trying to code a way of checking the data then comparing my calculated checksum to the UART received checksum value.
According to the manufacturer's datasheet, the equation is as follow:
Check value=(invert( Byte1+Byte2+...+Byte7/Byte24))+1
Attempting to run this code ends in a system crash, as Byte24 is always 0, and I am trying to divide by it.
Maybe I am missing some knowledge on what they actually mean? I tried searching the forum previously and found no similar problem, so forgive me if this has been explained before.
Here is my code in question (all serial prints are for debugging):
if(mySerial.available()>0) { // Checks is there's any data in buffer
int byteLength = mySerial.available();
Serial.println(byteLength);
int preCheckData[byteLength];
for (int i = 0; i < byteLength; i++) { // Updates data from the sensor module to the table
preCheckData[i] = mySerial.read();
};
int chkSum = (~(preCheckData[1]+preCheckData[2]+preCheckData[3]+preCheckData[4]+preCheckData[5]+preCheckData[6]+preCheckData[7]/preCheckData[24])+ 1);
Serial.println(String(checkSum)); // Crashes at this point when calculating chkSum
limitListener(); Serial.println(preCheckData[25]);
}
Device: Wemos D1 Mini