PDA

View Full Version : SERIN issues when recieving data from a LCD / Keypad device



Loki008
03-16-2010, 03:36 AM
I am using the crystalfontz CFA633 display which is a serial display with 6 buttons. I am attempting to read the button presses using the SERIN command but i am getting less that stellar results. I was hoping someone would be able to provide any suggestions on what could be causing an issue with this approach

Here is the code i am using, it is borrowed from the thread below from the crystalfontz forums that i found.



' {$STAMP BS2}
' {$PBASIC 2.5}
'Notes; Any change in commands to Display means CRC must be recalculated
BAUD CON $4020 'Set Baud rate to 19200 inverted
packetstring VAR Byte(10)
packettest VAR Byte
Main:
begin:
SEROUT 0,BAUD,[7,16,"Ready to Start? ",$B7,$8E] ' waits for user to press GO button.
SEROUT 0,BAUD,[8,16," ",$59,$E7]
SERIN 1,BAUD,[WAIT($80),STR packetstring\3]
PAUSE 20
DEBUG DEC packetstring
SEROUT 0,BAUD,[7,16,"Packet Received ",$C6,$16]
PAUSE 1000
IF packetstring(0)=$0 THEN
GOSUB buttonpressed
ELSEIF packetstring(0)=$1 THEN
GOSUB pressedup
ELSEIF packetstring(0)=$2 THEN
GOSUB presseddown
ELSEIF packetstring(0)=$3 THEN
GOSUB pressedleft
ELSEIF packetstring(0)=$4 THEN
GOSUB pressedright
ELSEIF packetstring(0)=$5 THEN
GOSUB pressedenter
ELSEIF packetstring(0)=$6 THEN
GOSUB pressedcancel
ENDIF

GOTO Main
buttonpressed:
SEROUT 0,BAUD,[7,16,"Pressed a Button",$01,$3D]
PAUSE 2500
RETURN
pressedup:
SEROUT 0,BAUD,[7,16,"Up ",$2E,$01]
PAUSE 2500
RETURN
presseddown:
SEROUT 0,BAUD,[7,16,"Down ",$0F,$9B]
PAUSE 2500
RETURN
pressedleft:
SEROUT 0,BAUD,[7,16,"Left ",$32,$DE]
PAUSE 2500
RETURN
pressedright:
SEROUT 0,BAUD,[7,16,"Right ",$CE,$32]
PAUSE 2500
RETURN
pressedenter:
SEROUT 0,BAUD,[7,16,"Enter ",$97,$BD]
PAUSE 2500
RETURN
pressedcancel:
SEROUT 0,BAUD,[7,16,"Cancel ",$45,$41]
PAUSE 2500
RETURN
END

·What is happening is when the·button press works, i get the correct value, say "4" for left. When it doesnt work i get the value of·"64" through the debug console.

Below are·links to the spec sheet for the display, as well as where i found the source code for interfacing with the basic stamp.


http://www.crystalfontz.com/products/633/datasheets/1139/CFA633-RMC_v2.0.pdf
http://www.crystalfontz.com/forum/archive/index.php/t-6229.html

Mike Green
03-16-2010, 03:47 AM
I think the display is reporting the keypresses as individual bits in the returned value. These would be $01, $02, $04, $08, $10, $20 or their decimal equivalents 1, 2, 4, 8, 16, 32. Try those instead of 1, 2, 3, 4, 5, 6. Remember that you can press more than one button at a time and the display will send you the sum of all the button values.

Loki008
03-16-2010, 03:53 AM
Mike Green said...
I think the display is reporting the keypresses as individual bits in the returned value. These would be $01, $02, $04, $08, $10, $20 or their decimal equivalents 1, 2, 4, 8, 16, 32. Try those instead of 1, 2, 3, 4, 5, 6. Remember that you can press more than one button at a time and the display will send you the sum of all the button values.
Doesnt look like it, if i press the left button, it will return "3" and go left, when it works. the rest of the time when it doesnt work, no matter what button i press i get "64"

Loki008
03-16-2010, 04:05 AM
Also if i increase the length of the string, to say 10, i have to press the button twice for it to register but it appears to work 100% of the time.

Loki008
03-17-2010, 07:40 AM
From what i can tell after doing some debugging is that for some reason the serial connection does not seem to get in / stay in sync. Does anyone have any suggestions on how to better capture·/ transmit·the serial data packets?