Communicating between two PICAXES

fizzit

Member
This is really wierd. I have my PICAXE 18X and 28X1 connected to communicate serially, but it doesn't work very well. Here is the code on the 28X1:

serin 0,N2400,("go")
high 7
pause 100
low 7
pause 100
serout 4,N2400,("go")
serin 0,N2400,(b0)
high 7
pause 200
low 7
serin 0,N2400,(w6)
high 7
pause 500
low 7
pause 500

and on the 18X:

serout 7,N2400,("go")
serin 6,N2400,("go")
high 3
pause 100
low 3
pause 100
serout 7,N2400,(b8)
pause 300
serout 7,N2400,(w6)

The LED on output 7 for the 28X1 blinks once, and then the one on output 3 of the 18X, but it doesn't blink again. It hangs on the serin for b8. b8 is always a number from 10 to 70. Why is my text but not my bytes being sent?
 

moxhamj

New Member
Hmm - serin will hang a picaxe and you have serin's on both chips so there are two opportunities to hang chips. So - if there are any opportunities to hang a chip, it will happen and the whole comms system fails. So says Mr Murphy.

Can you go back to a one-way comms system first just to test things? Just a simple serin and serout and send a byte? That will test if b8 is going through (I'm thinking of subtle clock differences between the chips).

The serin hang is a real problem. The newer chips get around it but they are more expensive.
 
Last edited:

Brietech

Senior Member
Yeah, you likely just have a software race-condition. Is your goal just to get the two microcontrollers to "handshake" before exchanging data? There are much saner ways to do that (perhaps a request and grant line?).
 

Peter M

Senior Member
try a longer pause before each serout just to make sure each serin is ready before you start transmission
 

retepsnikrep

Senior Member
Looks like you have fallen into the Serin/Serout REV-ED brackets trap as well, it caught me out as well. :(

Serin does not have brackets round a simple incomming variable unless it is a qualifier

serin 1,N2400,b1

Serout does :rolleyes:

serout 1,N2400,(b1)

Don't ask me why!!!!!

Treble check the manual for Serin/Out
 
Last edited:

kamilan

Member
bracket

Yeah,

I found that too with the brackets. I've looked at the code, and the delays are long enough.

Something that always helps is qualifiers.
 

westaust55

Moderator
For the 28X1 (and any other X1 and X2 parts), there is an optional timeout function for the SERIN command. That may help you get out of a hang-up situation wehre both PICAXE are waiting for each other. The 28X1 could then resend some data and go back to the SERIN and wait again.

SERIN [Timeout, address], pin, baudrate, (qualifier), variable
The Timeout is a value in milliseconds and the address is the label where control is redirected to if the SERIN does time out.
As already mentioned, try using qualifiers to indicate valid data follows.
 

hippy

Ex-Staff (retired)
It's the brackets as retepsnikrep says in post #5. It catches me out as well. "serin 0,N2400,(b0)" will wait for a byte to be received which has the same value as b0 before continuing ( zero in this case ).

Take care with sending and receiving 'w6'; serial only sends byte data.
 

fizzit

Member
Yeah, it was the brackets. Sorry for wasting your time.

I don't think there is really a race going on because I have those pauses. However, I'll keep that in mind.
 

fizzit

Member
Gah. Not worth posting a new thread for, but still really frustrating. I think w6 is being corrupted. I have the reciever doing:
serin 0,N2400,b0
serin 0,N2400,w6
and the sender doing:
serout 7,N2400,(b8)
pause 20
serout 7,N2400,(w6)
and b8 gets across fine, but w6 is outputting as something from 600 to 1000 and the reciever is recieving very odd numbers with a maximum of 232. This makes me think that a bit or a few is being cut off, but why and how?? Can anyone help with this?
 

manie

Senior Member
Fizzit: Look at post #8, last sentence from Hippy...... serial sends/receives bytes ONLY. If you must send a WORD value then send b12 and b13 instead of W6 and receive b8 and b9. Hang in there, you'll get it right....
 

eclectic

Moderator
Gah. Not worth posting a new thread for, but still really frustrating. I think w6 is being corrupted. I have the reciever doing:
serin 0,N2400,b0
serin 0,N2400,w6
and the sender doing:
serout 7,N2400,(b8)
pause 20
serout 7,N2400,(w6)
and b8 gets across fine, but w6 is outputting as something from 600 to 1000 and the reciever is recieving very odd numbers with a maximum of 232. This makes me think that a bit or a few is being cut off, but why and how?? Can anyone help with this?
Please read

Manual 1 page 45
Manual 2 page 10
then, run this little program in the Simulator.

e
 

Attachments

fizzit

Member
Don't you mean send b13,b12 and recieve b13,b12, because that's the way the variables are constructed? or would you do serin 0,N2400,b12,b13?
 

atharvai

Senior Member
yea i hate the serout thing as well. i always get worked up about it and then realise oh its 8bits only! not all 16 in a word!
 

kamilan

Member
use this,

serin 0,N2400,#w6

w6 is made up of b12 and b13. Which means if you send the integer 600 you are not sending "600" as a whole therefore the b12 = "6" and b13 = "0" and I think the last 0 gets omitted.

Remember that serin will take the first 8 bytes and put that into b12. By using #w6 serin will take continue to read bytes into w6 meaning you can send the integer 600

I had a similar problem with ascii characters and integers.

This worked for me.
 

westaust55

Moderator
From the link that BB gave in post 11, Hippy stated:
Using "SERIN pin,baud,#w0" will read a stream of decimal digit 8-bit characters up to a non-digit character and convert the received representation into a 16-bit number value stored in w0.
So if there were a SEROUT command sending #w6 and w6 contained the value 23,456
Then #W6 sends this as 5 bytes with ASCII codes for “2”, “3”, “4”, “5” and “6”

From Hippys statement, I interpret that as:

SERIN with #w0 will read in these ASCII characters (ie decimal digit 8-bit character?) and do a form of ASCII to Binary conversion to reconstitute the number in variable w0 as 23,456.

Something to try this evening
 
Last edited:

kamilan

Member
Hey,

No sorry, I wasn't meaning it as ASCII character, I was meaning it as individually...

so it sends the integer 6 as a set of 8 bits, then the integer 0 as a set of 8 bits.
 

BeanieBots

Moderator
Let's say w0 contains 1234.

If you do serout pin,baud,b0,b1 and recieve it with serin pin,baud,b0,b1
all will be well. Two 8-bit bytes gets transferred.

If you do serout pin,baud,#w0 and receive it with serin pin,baud,#w0
it won't quite work. The individual ASCII chars "1","2","3" & "4" will be sent and recieved but the receiver will sit waiting for another non numeric character to terminate.

serin pin,baud,#Var is useful when using a terminal program for entering numbers but the numer needs to be terminated with something like a carriage return befrore the serin knows when to stop getting characters.
 
Last edited:

fizzit

Member
NOOOOOOOOOOOOO!!!

I was testing a circuit with an 08m, 28X1, and 18X and it wasn't working the way it was before I made some changes. I had them all connected to a lm7805 and decided to try directly powering them from my power supply. I had been inputting 12v to the regulator - and I forgot to turn it to 5. The current jumped to 450ma and the 18X became hot. I quickly disconnected them. They were only connected for a couple of seconds! Yet, none but the 08m will take a program or do anything at all. I assume I'll have to buy new ones now...
:(:(:(:(
 

BeanieBots

Moderator
High voltage on a semiconductor is like a hammer on glass. The damage is usually very quick and obvious. However, even it doesn't 'shatter' it may well be cracked and waiting to break later. If your 28X1 was given a dose of 12v, put it to one side and be aware that it may some faults.
Personally, I'd bin it as a matter of course, the risk of it letting you down later is just too high.
 

fizzit

Member
Yeah... I'm not even going to try using the ones I overvolted in a project. I was talking about the one I had ordered as a replacement, and as it turns out, I had the reset pin tied low instead of high :p
 
Top