Sending Word variables using serial RF link.

artswan

Member
Just thought this might be helpful for those trying out using serial and RF links with Picaxe chips. Here are a couple of very short and simple code snippets that are the basis for me successfully sending Word variable information using simple serial RF links such as readily available and cheap TX/RF module pairs. A Picaxe-08M was used with this code.

Sending information via RF Link:
This snippet is the basic serout command with "wakeup string" (85,85,85,85) and identifier ("ABCDEF") and the word variable w0 broken down to it's constituent b0 and b1. Notice that b0 is sent BEFORE b1 for proper operation.

Main:
readadc10 4, w0
serout 2, N2400, (85,85,85,85,"ABCDEF",b0,b1)
pause 200
goto Main

End



Receiving information via RF link:
This is the corresponding receiver snippet. Again, using a Picaxe-08M.

Main:
serin 1,N2400,("ABCDEF"),b0,b1
sertxd(#w0," , ")
pause 200
goto Main

End


I hope this information helps. :)
 

manuka

Senior Member
Great - many of us add an extra ~5ms PAUSE to help settle the "I'm awake- now what" receiver.
 

sages

Member
Notice that b0 is sent BEFORE b1 for proper operation.
apart from both the sending code and receiving code needing to encode and decode the hi and lo bytes ( b0, b1 ) is there any other significance to the statement above?
 

westaust55

Moderator
My past projects found that the inclusion of a pause between the preamble and data gave better data transfer reliability.

See post 17 here:
http://www.picaxeforum.co.uk/showthread.php?t=11749&page=2




I concur with sages and question the b0 then b1 sequence for "proper operation" statement.
The thread title states word variables.

Within the PICAXE BASIC, the most significant byte is the odd numbered byte and the LSB is the even numbered byte.
So for most significant byte first, b1 and then b0.

For most non-PICAXE items that I have interfaced a PICAXE with, it is necessary to send the most significant byte first.
 
Last edited:

artswan

Member
apart from both the sending code and receiving code needing to encode and decode the hi and lo bytes ( b0, b1 ) is there any other significance to the statement above?
Yes. I searched other literature online concerning the proper code and some were vague on this, which caused me much extra time in "debugging". Just wanted to make extra clear what worked for me.
 

hippy

Ex-Staff (retired)
It doesn't really matter whether MSB is sent before LSB or MSB is sent after LSB providing that both the receiver and transmitter are in agreement and each matches the other.

In general I would say, where one has the choice, it is better to put the MSB on the left of a PICAXE statement, LSB to its right.

The PICAXE is "little endian" in that the LSB of a word (w0) is stored in the lowest numbered variable (b0) and the MSB in the higher (b1), and that is also the case for WRITE, READ, POKE and PEEK when using word data the LSB goes to the address specified, the MSB goes to the next higher address.
 
Top