CRC value examples - 635

deltaxfx

New member
Ok,
I think I have read every thread on this forum, and the manual for the 635, and various other sites about CRC.
I understand what CRC is, we use it in SATCOM all the time... but Im trying to figure out how its calculated for the 635. The perl example code doesnt seem to work properly. Ive used a few example programs from this site, but I want to figure it out, if nothing else, then for the personal gratification of it...
If someone could please let me know what the correct CRC values are for a couple different data types...
Like an 'OK' keypad press, the send CRC value and the return value.
And CRC values for some text being sent to the display, and its return value

Then I can test out code as I write it and make sure Im getting the correct values.

Thanks!
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 

jwilson

New member
Ok,
I think I have read every thread on this forum, and the manual for the 635, and various other sites about CRC.
I understand what CRC is, we use it in SATCOM all the time... but Im trying to figure out how its calculated for the 635. The perl example code doesnt seem to work properly. Ive used a few example programs from this site, but I want to figure it out, if nothing else, then for the personal gratification of it...
If someone could please let me know what the correct CRC values are for a couple different data types...
Like an 'OK' keypad press, the send CRC value and the return value.
And CRC values for some text being sent to the display, and its return value

Then I can test out code as I write it and make sure Im getting the correct values.

Thanks!
Hello.

Here is what I'm currently using, altho it's in C source. I took this straight from the 635 Data Sheet and it appears to be working great on this end. I've included some sample code that should build under just about anything. It includes the crc routine and well as a somewhat practical example that would be appropriate for the 635. It's quick and dirty and does virtually no error checking, so be kind. ;)

Here's an example. For function 31, at row 0 and col 0, with a string of "Hello":

[asus] ~/CRC/tmp> ./test "Hello"
packet.command: 31
packet.data_length: 7
packet.data[0]: 0
packet.data[1]: 0
packet.data[2] -> [6]: "Hello"
packet CRC: df0e

Hope this helps at least a bit,
John.
 

Attachments

deltaxfx

New member
Thanks for the example. I dont think I see yet what is going on to generate the CRC.
I read the manual for the 635, but I need it elaborated on.
A perl program was posted on this forum (thanks!) and has a packet generator in it, here is the code to generate the CRC:

Code:
my ($type,$paramdata) = @_;
	my $finalpacket;
	my $data = pack 'a*',$paramdata;
	my $length = length($data);
	my $packet = pack 'C2a*',$type,$length,$data;
	my $crc = 0xFFFF;
	
	foreach my $char (split //, $packet)
		{
		# & is bitwise AND
		# ^ is bitwise XOR
		# >> bitwise shift right

		$crc = ($crc >> 8) ^ $CRC_LOOKUP[($crc ^ ord($char) ) & 0xFF] ;
	        }

	# get the complement
	$crc = ~$crc ;
	$crc = ($crc & 0xFFFF) ;

	$finalpacket = $packet.chr($crc & 0x00FF).chr($crc >> 8);
Here is what I see/my questions about it...
the 'type' 'length' and 'data' that is sent to the lcd is packed into the variable '$packet' though i don't understand what the 'C2a*' is for. My perl book says the 'C' is a "signed/unsigned byte value" and the 'a' is a "byte string, null-/space-padded" So if someone could explain what exactly the "C2a*" is and why its needed, that would be great.
I dont get why '$crc' is set to 0xFFFF to start with. So of course this:
$crc = ($crc >> 8) ^ $CRC_LOOKUP[($crc ^ ord($char) ) & 0xFF] ;
Doesnt make much sense to me :p
Is the $crc variable shifted 8 places to make room for the crc data?
I see it is looking up a crc value from the table, but why in this part is it anded "&" with 0xFF?
Why after the compliment is "$crc = ($crc & 0xFFFF) ;"
I know I could just use the code and write a program with it. But I really want to understand it.
Thanks everyone!
 
USB LCD Displays - Graphic and Character LCDs with a Keypad

deltaxfx

New member
I understand CRC, just the coding is giving me some difficulty.
I added a bunch of prints to the PERL code I listed. In the data below, 'position' is the position in the CRC_LOOKUP array. 'crc value' is the actual value at that position in the array, and 'running crc' is the current computed CRC.
This again is for "Hello" at Row 0, Col 0, Type 31.
This yields the same result as jwilson got with his C code, and the same result that the 635 C test program yields.
Of course I have a question about it... The very first operation is ((0xFFFF >> 8) ^ 0xe70) (same thing in C and PERL) which both the C and PERL programs say is 0xe7f1... however if you use a hex calculator it comes out to be 0xe8f
Since the programs get 0xe7f1 as a result I just did (0xe7f1 ^ 0xFF) and that comes out to 0xe70e, obviously not the same as the original CRC value of 0xe70.
What causes this discrepancy? Both the C and PERL have the same logic (coded in their respective languages) and achieve the same result. But when done by hand (with a calculator) that result is different.
edit- I did this long hand, on paper, and it still comes out the same, which MATCHES the calc, but not the program.
0000|0000|1111|1111 = 0xFF
0000|1110|0111|0000 = 0x0e70
-------------------------------------------
0000|1110|1000|1111 = 0x0e8f

Code:
position: 0xee    crc value: 0xe70         running crc: 0xe7f1
position: 0x59    crc value: 0xcf44        running crc: 0x925e
position: 0x69    crc value: 0xfec7        running crc: 0xbb69
position: 0x7c    crc value: 0xb9eb        running crc: 0xfe7c
position: 0x11    crc value: 0x108         running crc: 0x7759
position: 0xfd    crc value: 0x2c6a        running crc: 0xfb98
position: 0x3c    crc value: 0xfbef        running crc: 0xb150
position: 0x32    crc value: 0x1291        running crc: 0xfb5e
position: 0x9e    crc value: 0x7df7        running crc: 0x20f1
final: 0xdf0e
 
Last edited:
Top