sx/b WAIT routine
nick bernard
Posts: 329
the lack of WAIT complicates things a bit when doing a SERIN sentence decoding.
i wrote a receive routine for a simple serial protocol but it doesnt seem to work. can i get a second opinion on it?
'receive a single byte, store to bx & buffer
RXBYTE:
ax = __PARAM1 ' buffer address
SERIN rxPin, Baud, bx, 20, RXB_TimeOut ' rx byte, wait 20ms until timeout
buffer(ax) = bx ' move byte to buffer
goto RXB_END ' success
RXB_TimeOut: ' failure
bx = 0
RXB_END:
RETURN
'Loads Sentence into Buffer, bx returns 0 on failure
Receive:
RXBYTE 0 'Receive C
IF bx <> "C" THEN
GOTO Re_Failure
ENDIF
RXBYTE 1 'Receive X
IF bx <> "X" THEN
GOTO Re_Failure
ENDIF
RXBYTE 2 'Receive Station
RXBYTE 3 'Receive Command
RXBYTE 4 'Receive Value hi byte
RXBYTE 5 'Receive Value lo byte
RXBYTE 6 'Receive % end of sentence
IF bx <> "%" THEN
GOTO Re_Failure
ENDIF
GOTO Re_End
Re_Failure:
bx = 0
Re_End:
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If I lived back in the wild west days, instead of carrying a six-gun in my holster, I'd carry a soldering iron. That way, if some smart-aleck cowboy said something like "Hey, look. He's carrying a soldering iron!" and started laughing, and everybody else started laughing, I could just say, "That's right, it's a soldering iron. The soldering iron of justice." Then everybody would get real quiet and ashamed, because they had made fun of the soldering iron of justice, and I could probably hit them up for a free drink. - Jack Handy
i wrote a receive routine for a simple serial protocol but it doesnt seem to work. can i get a second opinion on it?
'receive a single byte, store to bx & buffer
RXBYTE:
ax = __PARAM1 ' buffer address
SERIN rxPin, Baud, bx, 20, RXB_TimeOut ' rx byte, wait 20ms until timeout
buffer(ax) = bx ' move byte to buffer
goto RXB_END ' success
RXB_TimeOut: ' failure
bx = 0
RXB_END:
RETURN
'Loads Sentence into Buffer, bx returns 0 on failure
Receive:
RXBYTE 0 'Receive C
IF bx <> "C" THEN
GOTO Re_Failure
ENDIF
RXBYTE 1 'Receive X
IF bx <> "X" THEN
GOTO Re_Failure
ENDIF
RXBYTE 2 'Receive Station
RXBYTE 3 'Receive Command
RXBYTE 4 'Receive Value hi byte
RXBYTE 5 'Receive Value lo byte
RXBYTE 6 'Receive % end of sentence
IF bx <> "%" THEN
GOTO Re_Failure
ENDIF
GOTO Re_End
Re_Failure:
bx = 0
Re_End:
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If I lived back in the wild west days, instead of carrying a six-gun in my holster, I'd carry a soldering iron. That way, if some smart-aleck cowboy said something like "Hey, look. He's carrying a soldering iron!" and started laughing, and everybody else started laughing, I could just say, "That's right, it's a soldering iron. The soldering iron of justice." Then everybody would get real quiet and ashamed, because they had made fun of the soldering iron of justice, and I could probably hit them up for a free drink. - Jack Handy
Comments
WAITFOR:
· temp1 = __PARAM1
· DO
··· SERIN Sin, Baud, temp2
· LOOP UNTIL temp2 = temp1
· RETURN
In your application you can:
· WAITFOR "C"
Now, if you·are expecting things to arrive within a given window, you could do something like this that would cause WAITFOR to return a success code if it worked:
WAITFOR:
· temp1 =·__PARAM1
· DO
··· SERIN·Sin, Baud, temp2, 20, NO_RX
· LOOP UNTIL temp2 = temp1
· temp1 = 0
· GOTO WAITFOR_EXIT
NO_RX:
· temp1 = $FF···
WAITFOR_EXIT
· RETURN temp1
One thing I did notice is that you don't update your buffer pointer after receiving a byte.· Perhaps you should add "INC ax" afer you move bx into the buffer.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
last things first.
One thing I did notice is that you don't update your buffer pointer after receiving a byte. Perhaps you should add "INC ax" afer you move bx into the buffer. - __PARAM1 of RXBYTE = pointer for buffer.
You could always create a WAITFOR subroutine: i'm using a terrific little 485 tranceiver so sentence handling is very important. i like your second recommendation. i will give it a shot. the code i wrote works , but there's always room for improvement and i love they way your code is easily readable by people with weak programming experience
thx for you time, nick
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If I lived back in the wild west days, instead of carrying a six-gun in my holster, I'd carry a soldering iron. That way, if some smart-aleck cowboy said something like "Hey, look. He's carrying a soldering iron!" and started laughing, and everybody else started laughing, I could just say, "That's right, it's a soldering iron. The soldering iron of justice." Then everybody would get real quiet and ashamed, because they had made fun of the soldering iron of justice, and I could probably hit them up for a free drink. - Jack Handy
Post Edited (nick bernard) : 8/12/2005 7:58:05 PM GMT