Sending a word variable from an 08m2 to a 28x2. Help please?

Oarsome

New Member
Hello there,
I've already trawled through other forum posts and the picaxe manuals but I can't find anything simple enough for my simple brain to understand.
All I want to do is send w1 and w2 from the 08m2 to the 28x2, I have tried to start with the serout and serin commands but I am not sure how to use them in tandem.
Any help will be much appreciated :)

Joe
 

westaust55

Moderator
Assuming you are looking at a hard wired (not wireless) connection then the requirements are simple:
1. Wiring - a wire from the desired output pin of the 08M2 to the desired input pin of the 28X2.
Also connect the Gnd/0V lines of both PICAXE chips together if not on the same supply.
2. Some lines of code.
(A) for Tx side - sending the low and high byte of each word variable separately
SEROUT <pin>, baudrate, (b2,b3,b4,b5)
(B) For the Rx end
SERIN <pin>, baudrate, b2,b3,b4,b5 ; note no brackets

For <pin> see PICAXE manual1 pages 9 to 11 to ascertain which pins can be inputs and/or outputs on each chip.
For baudrate suggest start with N2400 and adjust later once your code is working
 

Oarsome

New Member
I've got them both on the PICAXE project board, all I want it to do now for test purposes is to light up an LED when the variable is correct.
How do I change the word variables into byte variables, am trying to send w1 = 24328.
 

russbow

Senior Member
A word variable consists of two consecutive byte variables. From manual 2, page 10

However for larger numbers two byte variables can be combined to create a word
variable, which is capable of storing integer numbers between 0 and 65535
inclusive. These word variables are labelled w0, w1, w2 etc... and are constructed
as follows:
w0 = b1 : b0
w1 = b3 : b2
w2 = b5 : b4
w3 = b7 : b6
etc...
Byte variable maximum value is 255, so you need to use word only if the value stored exceeds this.

So your W1 is actually b3:b2
 

Oarsome

New Member
This is what i have written now, still not getting something right.

the top one is for the o8m2 and the bottom one is for the 28 x2

start:
b3:b2 = 24328
high c.2
if pinc.3 != 1 then : goto start : endif
serout c.1, N2400, (b3,b2)
goto start

start:
pause 50
if pinb.6 != 1 then : goto start : endif
high b.7
pause 50
serin b.5, N2400, b3, b2
if b3:b2 = 24328 then : high b.4 : endif
low b.7
pause 1000
low b.4
goto start
 

MartinM57

Moderator
I expect...

b3:b2 = 24328
^

Error: Syntax error in this line!

...although w1 is comprised of b3 and b2, you can't use that notation in the code
 

westaust55

Moderator
with: " w1 = 24328 "

b2 automatically holds the low byte and b3 holds the high byte of the word value.

in effect:
b3 = 24328 / 256

b2 = 24328 // 256 which is the equivalent of b2 = 24328 - (b3 * 256)
 

Oarsome

New Member
if i put this program in i get the flashing led.
08m2
start:
b0 = 50
high c.2
if pinc.3 != 1 then : goto start : endif
serout c.1, N2400, (b0)
goto start

28x2
start:
pause 50
if pinb.6 != 1 then : goto start : endif
high b.7
pause 50
serin b.5, N2400, b0
if b0 = 50 then : high b.4 : endif
low b.7
pause 1000
low b.4
b0 = 0
goto start



If i put this one in i get nothing.

08m2
start:
w0 = 24328
high c.2
if pinc.3 != 1 then : goto start : endif
serout c.1, N2400, (w0)
goto start


28x2
start:
pause 50
if pinb.6 != 1 then : goto start : endif
high b.7
pause 24328
serin b.5, N2400, w0
if w0 = 24328 then : high b.4 : endif
low b.7
pause 1000
low b.4
w0 = 0
goto start
 

hippy

Ex-Staff (retired)
One trick for easily handling the msb and lsb bytes is to define them via SYMBOL definitions; for example w1 is made up from b3 (MSB) and b2 (LSB) so ...

Code:
Symbol value     = w1
Symbol value.lsb = b2
Symbol value.msb = b3

value = 12345
SerOut C.1, N2400,( value.msb, value.lsb )
At the receiving end ...

Code:
Symbol value     = w1
Symbol value.lsb = b2
Symbol value.msb = b3

SerIn B.5, N2400, value.msb, value.lsb
 

Oarsome

New Member
I still don't understand what I am doing wrong

symbol value = w1
symbol value.lsb = b2
symbol value.msb = b3

start:
value = 24328
high c.2
if pinc.3 != 1 then : goto start : endif
serout c.1, N2400, (value.lsb, value.msb)
goto start




symbol value = w1
symbol value.lsb = b2
symbol value.msb = b3

start:
pause 50
if pinb.6 != 1 then : goto start : endif
high b.7
pause 24328
serin b.5, N2400, value.lsb, value.msb
if value = 24328 then : high b.4 : endif
low b.7
pause 1000
low b.4
value = 0
goto start
 

Oarsome

New Member
i just noticed the pause 24328 in there, ive taken it out now and now it works yay!!! Thank you everyone for your input
 
Top