Host Engineering Forum
General Category => Do-more CPUs and Do-more Designer Software => Topic started by: MarkTTU on September 11, 2015, 08:30:19 PM
-
I'm reading in a string via serial. Have managed to get all the data in and split out into D memory like I need it, but I'm having a hard time trying to do a check on the CRC I'm getting with the string.
String is 18 bytes.
Byte 1 = Not Used / Don't care
Bytes 2-17 = Data I care about and am successfully pulling out of the string
Byte 17 = CRC = inverse of the sum of bytes 2 to 17 so that the 8 bit sum of bytes 2 to 17 + CRC = 0
I've managed to use the STRGETB command to pull out byte 17 and put it into D0. Problem I have is I'm not sure how to calculate the 8 bit sum of bytes 2-17. Once I've got that I figure I can use a MATH instruction to add the two together and see if I get 0 or not. Any ideas?
-
Create a byte block. Use STRGETB to move data from the string to the byte block. Use MATH's SUM function the sum the array in one instruction.
-
CHECKSUM should work on the existing D memory buffer. Based on your description, it looks like the checksum is in Byte #18, not byte #17, which is data? I have written the logic below assuming byte #17 is data and byte #18 is the checksum byte.
Note that Do-more uses 0-based offsets, not 1-based offsets. Hence Byte #2 is Offset 1, Byte #18 is Offset 17 (this is probably the source of 17 vs. 18, since you stated that you had extracted checksum at the 18th byte, at offset 17 ;D).
CHECKSUM
On Buffer: D0
Function: CheckSum:8
Initial Value: 0
Starting Offset: 1 // 0-based offset
Ending Offset 17 // 0-based offset, INCLUDES the Checksum byte; make it 16 to NOT include the checksum byte
Destination V0
V0 should equal 0 when you include the checksum byte
-
Was reading this on my phone...without glasses...and missed stuff. You can use the MATH SUM, and then either output to a byte, or use a cast to pick the low byte from the non-byte target.
As for CHECKSUM, I assumed you didn't use it because it didn't do what you needed...but it will definitely add bytes. So yeah, what Franj said.