Xbee help
Carl Lawhon
Posts: 36
This may be a noobish question, but here goes. I have two protoboards and have two xbees hooked up to the protoboards. I need one protoboard to be able to send a·latitude coordinate and a longitude coordinate, obtained from a Parallax GPS receiver, to the other protoboard. Any suggestions? ·
Comments
You might use a unique lead-in for each "packet" of information like the character '!' and discard all received characters until that one is found before using the Extended FullDuplexSerial routines to handle the actual values. This would help you if one end of the "conversation" gets confused. It just ignores everything until something makes sense.
On the sending side you could so something like:
serial.tx(ESCAPE_CHAR)
serial.tx(ESCAPE_CHAR) 'I like to send the escape twice so the receive side knows it is at the beginning of a new packet
serial.tx(latitude & $FF)
serial.tx((latitude>>8)& $FF)
serial.tx((latitude>>16)& $FF)
serial.tx((latitude>>24)& $FF)
serial.tx((longitude)& $FF)
serial.tx((longitude >>8)& $FF)
serial.tx((longitude >>16)& $FF)
serial.tx((longitude >>24)& $FF)
On the receive end:
waint until serial.rx == ESCAPE_CHAR
if serial.rx == ESCAPE_CHAR
latitude := serial.rx
latitude |= serial.rx<<8
latitude |= serial.rx<<16
latitude |= serial.rx<<24
longitude := serial.rx
longitude |= serial.rx<<8
longitude |= serial.rx<<16
longitude |= serial.rx<<24
I couldn't find any exact snippets from my code, so this is untested, but this or something very similar has worked well for me in the past.