Yet another SERIN2 question
Howdy
I've fought this long enough - now am asking for help.
What I have is a serial LCD backpack with a keypad interface as well. Using a PIC 16F870 . That all works fine.
Sending serial characters, custom characters, etc to the LCD works fine.
The problem I have is getting data back from the keypad.
How it works is a request is sent to the keypad using a SEROUT2 command, ($FE,$1B,) an interrupt is returned, (active low), and after it goes high the key number is returned serially. This all works, I have attached a screen shot of the data transmissions from my logic analyzer.
What I can't get to work is the SERIN2 to actually get the key value back in.
As I said, the serial data (byte) is coming back, but the SERIN2 just "hangs", and never brings the data in.(must not see it) I tried using a timeout and label in the SERIN2 statement, but that was counter productive, 'cause the data was not being seen anyway.
here is a short code segment
serout2 Tx,84, [$FE,$1B] ' request for key data (code for this backpack)
pauseus 500
serin2 Rx,84,[key] ' get the key pressed from keypad buffer
pauseus 500
serout2 Tx, 84, [$FE,$0C,1,0,#key] 'display it on LCD line 2, position 1
key jas been defined as a byte variable
Tx is PORTC.7 and Rx is PORTC.6
The interrupt is returned to PORTC.5
4 Mhz oscillator is defined
The attached screen shot from my logic analyzer shows the interrupt line, data request, and serial data returned. A decimal "9" is what is returned in this case.
I've tried several variations of the SERIN2 command ( even tried SERIN with the "modedefs.bas" included )
Should I be trying to receive the data in an interrupt routine? That does not seem necessary - - -
Something simple, I'm sure - but I am stumped.
Thanks
Ken
Serin2 problem - figured it out !
Hi all
It must have been timing related. I revised the code to :
serout2 Tx,84, [$FE,$1B] 'Request data from Keypad
pauseus 100 ' added a short delay
serin2 Rx,84,10,cont,[key] ' put a Timeout & jump in so the SERIN2 will wait
' for a while for the data to come back
cont: ' label to "jump to" if no data
pause 50 'Not sure if this is needed, will play with it some
serout2 Tx, 84, [$FE,$0C,1,0,#key] 'the decimal key value is now displayed
' The keypad defaults to 0 if a request
'is made and no key pressed
Anyway, now it works great. Learned something in the process too !