How do I transmit a 16bit number?

Tyro

Member
A 16bit random number is generated and stored in EEPROM. This number can be transmitted via a short range RF link to a receiver and a picaxe. The receiver picaxe has a switch which when operated will cause the microcontroller to go into a “learn” mode.

The random number (transmitter ID code) is transmitted from the first device and the receiver picaxe memorizes and stores this number associated with the first transmitter. The number is transmitted again and if it is the same as the recently stored number, an OK beep is generated.

A second transmitter is activated and a second random number is generated. The receiver picaxe memorizes and stores this number and associates it with the second transmitter. This process continues until n (to be determined) transmitters are memorized. The learn mode is switched off.

Subsequently, if any transmitter sends its own random number, preceded by a suitable preamble to condition the receiver and alert the picaxe that a number will be coming next. The receiver picaxe will then do various things depending on which transmitter has sent the signal.

I am open to suggestions on what protocol could be used and how to strip out the n random numbers (transmitter ID codes).
 

SAborn

Senior Member
Send your preamble as hex and your Random number as Ascii code, then on the receieving end just read the ascii code, as the preamble of hex will be ignored and filtered out.

This will also help filter out some data collisions due to more than i transmitter.

Using ascii will also allow for your 16 bit number from 1 W? register.
If you send more than 1 ascii data package in a single transmittion than you need to send a block of hex between each ascii packet or the receiving end will not find the stop/start bits between each ascii packet

Use something like this example............

serout 0, T2400,($aa,$aa,#w1, $aa, #w2 ,$aa ,#w3, $aa,13,10)

And receive with something like this example......

serin RX ,T2400,#w1,#w2,#w3
 
Last edited:

westaust55

Moderator
Your 16-bit number will occupy a word variable such as w0 or w1.

Each word variable in fact comprises two 8-bit byte variable.
W0 = b1:b0 - most significant byte first
W1 = b3:b2, etc

It is not esential to convert these numbers to ASCII format first - that involves sending around 3 times as much data.

so if your 16-bit value is loaded into w3 then the byte variables are in b7 and b6

So after the pre amble and any qualifier

you can just sent the two byte variables

so
SEROUT pin, baud, ($55, $55, $55, $55)
PAUSE 10 ; change this to suit the baud rate 10 to 16 for 1200 baud
SEROUT pin, baud, ("ABC", b7, b6) ; "ABC" is the qualifer

at the receiving end:
SERIN pin, baud, ("ABC"), b7, b6 ; here the 16-bit value is returned in w3 at the receiving end.
 

Tyro

Member
Thank you SAborn and westaust55 for your help.

What is the qualifier "ABC" and is it necessary?
 

william47316

New Member
a qualifier is just the string serin etc looks for before it receives the main data and acts as a filter eg on RF receivers you get noise from the ether and unless you have a qualifier it will accept any data and have unpredictable or unusual results. usually with words you can send the individual byte variables it uses for that word variable and same at the other end, receiving them as bytes and using the associated word variable in the rest of the program, you may want to checksum the received value to make sure the data isnt majorly corrupted along the way, add the bytes together and divide the number of them and stick it in another transmitted byte and calculate and compare at the other end. i use this on a one way link for my 8 digit display
 

westaust55

Moderator
Great to read that your project is up and running as desired.

Also good that you provide some feedback - something many do not bother to do.
 
Top