serial communication between two picaxe 40x2

santhoshR

New Member
hi !!
I am trying to make a serial communication between two picaxe 40x2. But its not working. Here is the code :
Code:
'transmitter code
#picaxe 40x2
main:

if pinC.0 = 1 then 
serout D.1,N2400,("1")
end if

if pinC.1=1 then 
serout D.1,N2400,("2")
end if 

if pinB.7=1 and pinB.6=0 then
serout D.1,N2400,("3")
end if 

if pinB.6=1 and pinB.7=0 then
serout D.1,N2400,("4")
end if 
goto main
and the receiver code is :
Code:
#picaxe 40X2
main:
serin D.1,N2400,b1
if b1=1 then
high B.7
end if

if b1=2 then
high B.6
end if

if b1=3 then
high B.5
end if

if b1=4 then
high B.4
end if
goto main
Can anybody help me out with this problem !! ?
Thank You
 

srnet

Senior Member
Why not write a much simpler program for one 40X2 that does nothing but send a byte, pause a second or so and repeat.

Have the receiver program just doing a serin and flashing a LED (or printing to the terminal) when it recieves something.

Get that working and move on to trying the rest.

Simplify ........
 

Jamster

Senior Member
Your sending the ASCII value of 1/2/etc and looking for a normal number, get rid of the quote marks in the serout and it should work.
Jamster
 

geoff07

Senior Member
I just typed this and posted it whereupon it completely vanished. So now retyping!

The serin command is a blocking command, i.e. it just sits there awaiting input. As you are using a 40x2 you might want it to do something else meanwhile. You can do this if you send a short pulse before the character (from the tx chip) and set an interrupt on the rx chip that triggers serin only if it sees the pulse. You have to use an input pin that can trigger interrupts of course. There is an example in my solar controller code elsewhere in this forum. You share the same pin for the interrupt and for the character. If you have several sources coming in you can diode-mux them and they can all use the same pin. Use a check digit if you do in case of clashes.
 

westaust55

Moderator
The X1, X2 and M2 PICAXE parts have an optional [timeout] parameter for the SERIN command.
As such they need not be blocking as one can move on after a period of time and loop back at intervals.
But you may miss bytes and the program not respond correctly unless the sender/transmitter repeats data when away from the SERIN command too long.
 

santhoshR

New Member
@Jamster I ve tried this ...
Code:
#picaxe 40x2
main:

if pinC.0 = 1 then 
serout D.1,N2400,(1)
end if

if pinC.1=1 then 
serout D.1,N2400,(2)
end if 

if pinB.7=1 and pinB.6=0 then
serout D.1,N2400,(3)
end if 

if pinB.6=1 and pinB.7=0 then
serout D.1,N2400,(4)
end if 
goto main
the receiver code is the same .. still couldnt get it working ..
 

inglewoodpete

Senior Member
Your problem at the moment is that you have no idea what the receive end is receiving. If you can, leave the programming lead connected to the receiver after downloading the following code to it. The code will display every received character value in the Terminal window of the Programming Editor.

Code:
#picaxe 40X2
#Terminal 9600     'for a 20X2/28X2/40X2 at their default 8MHz
main:
serin D.1,N2400,b1
SerTxd ("Rec=", #b1, CR, LF)
if b1=1 then
   high B.7
end if

if b1=2 then
   high B.6
end if

if b1=3 then
   high B.5
end if

if b1=4 then
   high B.4
end if
goto main
 

westaust55

Moderator
@geoff07 Thank You for your reply.. are u asking me to use a qualifier ?
Geoff07 was, I believe, suggesting a form of interrupt where the program can do other tasks and when a pulse is received on the pin, the interrupt routine has a SERIN command to receive the data.

Qualifiers on the other hand can help filter out unwanted signals as it will wait for the "qualifier" match before accepting the following byte(s) as desired data.

But first do as IWP has suggested above and see what the receiver is in fact receiving.
 

santhoshR

New Member
Thanks everybody for your replies ... I HAVE SOLVED THE PROBLEM !!!
The problem is that the pin D.1 through which i did my serial transmission was not working.. the pin D.1 of this chip is not working for serial communication .. I dont know why.. If anybody knows this, then you can share it ..
the corrected code is
transmitter :

Code:
#picaxe 40x2
main:
if pinC.0 = 1 and pinB.7=0 and pinB.6=0 then
serout C.2,N2400,("1")
end if

if pinC.1=1 and pinB.7=0 and pinB.6=0 then 
serout C.2,N2400,("2")
end if 

if pinB.7=1 and pinB.6=0 and pinC.0=0 and pinC.1=0 then
serout C.2,N2400,("4")
end if 

if pinB.6=1 and pinB.7=0 and pinC.0=0 and pinC.1=0 then
serout C.2,N2400,("3")
end if 

if pinC.0=0 and pinC.1=0 and pinB.6=0 and pinB.7=0 then
serout C.2,N2400,("5")
end if 
goto main
Code:
'receiver
#picaxe 40X2
main:

serin C.2,N2400,b0

if b0="1" then
low C.6
low C.7
high C.4
low C.5
end if

if b0="2" then
low C.6
low C.7
high C.5
low C.4
end if

if b0="3" then
low C.4
low C.5
high C.6
low C.7
end if

if b0="4" then
low C.4
low C.5
low C.6
high C.7
end if

if b0="5" then

low C.4
low C.5
low C.6
low C.7
end if 

goto main
 
Top