hserin & serin on the same pin

steliosm

Senior Member
Hello all.

Is it possible to use hserin pin to receive background data and then revert this pin into normal pin to receive more data (eg, 8 bytes)?

I have a small program that checks with 'hserin wX' if a wake-up byte (ASCII 63) is background received and if so, then replies with a 'command prompt' and waits for an extra byte to be received using serin on the same pin. When the extra byte is received it sends it back to the serial and returns to the 'checking' loop. Although it seems to work fine, I have noticed that if I send the same wake-up byte as a 'data' byte then the program thinks it has just received another wake-up byte and displays the prompts to receive additional data.

Code for Picaxe 14m2:

Code:
' Pin symbols
symbol SER_IN  = B.1
symbol SER_OUT  = B.2

' Variable names
symbol COUNTER = b2
symbol SERINDATA = w6

' Configure the hserin pin for background serial in
hsersetup B4800_32, %00

main_loop:
' Loop to check for incoming data
for COUNTER = 1 to 20
  let SERINDATA = $FFFF
  hserin SERINDATA

  ' Check if we got the '?' character
  if SERINDATA = 63 then
    ' Get into serial-in mode
    gosub get_serial_data
  endif

  ' Make a pause
  pause 1000
next COUNTER
  
' Start again
goto main_loop

get_serial_data:
  do
    ' Get the serial data
    ' Send ACK prompt (">")
    serout SER_OUT, T4800_32, ("> ")
    serin SER_IN, T4800_32, b12
    serout SER_OUT, T4800_32, ("OK ", b12, " ", 10, 13)
  ' Loop over if the first character is "1"
  loop while b12 = "1"
return
Any tips?

Thanks,
Stelios
 

Technical

Technical Support
Staff member
When you use the hsersetup command the internal silicon module for the hardware serial port is connected internally. Therefore 'normal' input commands that rely on a high/low signal such as serin can be affected.
Therefore it is generally not a good idea to use both on the same pin.
 

hippy

Technical Support
Staff member
I haven't tried it but it should be possible. You will have to issue a HSERSETUP OFF to revert the pin back to an input.
 

steliosm

Senior Member
Technical, I was afraid of that but I though that serin temporarily disabled the background serial receive in order to process the data itself. Everything else about serin seems to work, the blocking that is actually. Debugger can't help on this one, since it cannot display the contents of the 2-byte fifo.
Hippy, thanks for the tip on the command. I can test this when I get back home and let you all know.
 

steliosm

Senior Member
Hello all again.

HSERSETUP OFF did the trick! Works great now.
This is how the subroutine looks like now:

Code:
get_serial_data:
  ' Disable background serial
  hsersetup off
  do
    ' Get the serial data
    ' Send ACK prompt (">")
    serout SER_OUT, T4800_32, ("> ")
    serin SER_IN, T4800_32, b12
    serout SER_OUT, T4800_32, ("OK ", b12, " ", 10, 13)
  ' Loop over if the first character is "1"
  loop while b12 = "1"
  ' Enable background serial
  hsersetup B4800_32, %00
return
Thank you Hippy.

Stelios
 
Top