• We recently switched our forum platform. If you experience any issues please email support@crystalfontz.com

CFA-635 CRC Question

Joe

New member
I just bought a CFA-635 and had it Programmed for serial TTL level. I hooked it up to WINTEST Through a Serial adapter board from Crystal Fontz, and it works great on WINTEST. But when I hooked it to a Basic Stamp 2 form PARALLAX, all that I can do is receive Information from the LCD. It will not respond to any Packets that I send it. Here is a test that I tried.

BAUD CON $4020 'Set Baud rate to 19200 inverted

PAUSE 4000
LOW 2
begining:
SEROUT 2,BAUD,[14,1,1,$DE86]
END

The CFA's RX Pin is hooked to the BS2's Pin 2.
I had to look up the CRC from the Packet Debugger on WINTEST.
What does the CRC consist of, how do I calculate it? I've looked at the data sheet but I don't understand how to calculate the CRC.

Joe :confused:
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 
USB LCD Displays - Graphic and Character LCDs with a Keypad

Joe

New member
Thanks, it will probably take some time for me to learn how to use a CRC, but it looks like that is what I need.

Joe
 

cggbs

New member
Joe,
Did you ever find a solution to your CRC problem? I just spent a lot of time with it and the parallax chips and have had some pretty good results.
 

Joe

New member
CRC with Basic

Not yet, but if you are using PIC's for CRC calculation especially if you are building the program in Basic, I would really appreciate seeing some of your work.

Joe
 

cggbs

New member
Joe,
Here is some code that shows how to send the CRC to the LCD. If the crc is $5B97 .... you have to split it into two and send the LSB first $97,$5B.

The comments in the code are probably not accurate but dont get hung up on them.


When i find the crc calculation code i will send it to you.
 

Joe

New member
CRC Calculation using basic stamp or PIC

Thanks!
If you could find a CRC calculation routine it would really be nice, because this has been driving me nuts.
 

cggbs

New member
Sorry for not having the BS2 code handy.......I switched to the JAVELIN so I could use the Virtual UART. It makes it possible to handle all of the temperature reporting. It also lets you have alot more variables. Still.......I had to learn JAVA and it drove me crazy, so I know just how you feel.
 

Joe

New member
Perhaps you might have some kind of formula or procedure to get a CRC? If you could tell me how it would really save a lot of head ache.

Thanks.
 

Joe

New member
How about this? Does it look like this would work, if so, how would I use it? It appears that I have to clear variable crc, then send each byte from a packet through the Calc_CRC Sub routine. The only problem is that it looks like it only generates an 8 bit crc. Could you tell me what you think?
Code:
' {$STAMP BS2p}
' {$PBASIC 2.5}

crc         VAR     Word
aByte       VAR     Byte
idx         VAR     Nib

crc = 0
aByte = 1

Main:
DEBUGIN  BIN aByte
GOSUB    Calc_CRC
DEBUG    DEC5 CRC,CR
GOTO    Main

Calc_CRC:
crc = (crc & $FF00) | (aByte ^ (crc & $FF))
FOR idx = 0 TO 7
  IF (crc.BIT0 = 0) THEN
    crc = crc >> 1
  ELSE
    crc = (crc >> 1) ^ $A001
  ENDIF
NEXT
RETURN
:rolleyes:
 

Joe

New member
Thanks for everybody's help, I found the answer to CRC-16 code for the BS2 and PIC's. Here it is... Test it against this sites calculator http://www.lammertbies.nl/comm/info/crc-calculation.html?crc=123456789&method=ascii:cool:
Code:
CRC		VAR Word
Calc		VAR Word
aByte		VAR Byte
Counter		VAR Nib

POLYNOMIAL	CON $A001

Main:
 CRC = 		$0000
 aByte = "1": 	GOSUB Calc_Crc
 aByte = "2": 	GOSUB Calc_Crc
 aByte = "3":	GOSUB Calc_Crc
 aByte = "4":	GOSUB Calc_Crc
 aByte = "5":	GOSUB Calc_Crc
 aByte = "6":	GOSUB Calc_Crc
 aByte = "7":	GOSUB Calc_Crc
 aByte = "8":	GOSUB Calc_Crc
 aByte = "9":	GOSUB Calc_Crc
 DEBUG		HEX crc
 END

Calc_Crc:
 FOR Counter =	0 TO 7
 Calc =		aByte ^ CRC & 1
 IF Calc =		0 THEN CRC_Add
 Calc =		POLYNOMIAL
 CRC_Add:
 CRC =		CRC / 2 ^ Calc
 aByte =		aByte / 2
 NEXT
 RETURN
 

Joe

New member
Oh! By the way, if anybody uses the above code, don't forget to change the polynominal to $8408 which is what the CFA-635 uses.
 

Joe

New member
Why does the WinTest program create crc's that are not even in the crc table examples in the documentation?
 

CF Tech

Administrator
I'm not sure I understand that post. Are you saying that the algorithm in WinTest is not listed in the data sheet, or that the output does not match?
 

Joe

New member
I Copied the CRC output from WitnTest, then I went to the datasheet for the CFA-635 and did a search for the CRC it did not find a match. Does WinTest modify the CRC just for transmission?
 
If you look at the formula in the data sheet sample, you can see that the table does NOT contain crc values. It contains numbers that give the crc after being xor'ed with the previous data.
 

Joe

New member
That makes sense. I forgot that they could not be 16 bit CRC values because there is only 256 values in the table.
 

Joe

New member
What do you mean by previous data? Do you mean the data added together then divided by the number of data bytes?
 
Top