PDA

View Full Version : Yet another SERIN2 question



ozarkshermit
- 31st March 2009, 16:24
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

ozarkshermit
- 31st March 2009, 16:38
can't seem to get this to work . .

ozarkshermit
- 31st March 2009, 16:41
Sorry - I did not attach this correctly

Ken

Archangel
- 31st March 2009, 17:24
Hi Ken,
We just saw something like this a month or so ago, and what I learned from that thread is serin2 must have a non numeric character follow the numeric data in order to continue on it's way.<br>
EDIT: AHAA I found it :http://www.picbasic.co.uk/forum/showthread.php?t=10786

ozarkshermit
- 31st March 2009, 17:46
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 !

Archangel
- 31st March 2009, 17:57
You have 4 open threads for the same problem ! WHY ? Please continue the saga within the original post, otherwise how do we know where to post our ideas as to how to help you.

SOMRU
- 31st March 2009, 20:11
Greetings
How about some code...
I'm use a system using 9 pics all using serin2/out2

Note after initiating the read pause for 10ms for the write.
This cured the universe for us.
other option is to use a single clock source.