simple serial problem

toxicmouse

Senior Member
Simple serial problem:

I just want to send a serial message between 2 picaxe 18M2s.

Transmitting picaxe is on a breadboard with nothing but the components for programming it (22k, 10k,socket), one LED to let me know it is working and a 15cm twisted pair of wires, one is grounded, the other is connected to c.3 (I also tried c.0)
Code:
'transmitter
b0 = 0
main:

low c.3 'bring the line low momentarily
pause 25 
serout c.3,N1200_4, (b0)
b0 = b0 + 1

'flash the LED once
low b.4
pause 100
high b.4
pause 100

goto main
For the receiver I have a CHI030 project board with a 18M2 with the incoming wire connected to c.4

Code:
'receiver
b1 = 0
main:
b0 = 0
serin [250,no_serial], c.4,N1200_4, (b0)  'if no serial message received then goto no_serial
sertxd ("received:",#b0,cr,lf)
goto main

no_serial:
sertxd ("Nix ",#b1,cr,lf)
b1 = b1 + 1
goto main
both chips use the same power supply, 5V from the same USB port.

the part that baffles me is that with this arrangement the receiving picaxe does not sertxd any message to the terminal window. When I disconnect the wire between the picaxes then the receiver displays "Nix #b1" nicely (the no_serial: part of the code).

Any idea what I am doing wrong?
 

hippy

Technical Support
Staff member
PinC.4 on an 18M2 is the Download Serial In pin so serial sent to that is probably causing the receiving PICAXE to enter its download mode and reset.

You can add a DISCONNECT command at the start of the program and it will probably resolve things but you will have to do a power-cycling Hard Reset to download subsequent programs into the PICAXE.
 

toxicmouse

Senior Member
PinC.4 on an 18M2 is the Download Serial In pin so serial sent to that is probably causing the receiving PICAXE to enter its download mode and reset.
Thanks Hippy. I have changed the receiver to pin c.1. I am now receiving "received:0" continuously instead of the value of b0 incrementing. Do I need a pull up resistor?
 
Last edited:

hippy

Technical Support
Staff member
You shouldn't need a pull-up. Perhaps try something simpler to start with which can be checked using terminal -

Code:
Tramsitter:
  Do
    For b0 = "A" To "Z"
      SerOut C.3, N1200, ( b0 )
      Pause 1000
    Next
  Loop
Code:
Receiver:
  Do
    SerIn C.1, N1200, b0
    SerTxd( "Received ", #b0, " ", b0, CR, LF )
  Loop
And make sure you have a 0V connection between each board.

Added: And having just made the same mistake myself. Use -

SerIn ... b0

Not -

SerIn ... ( b0 )

Your existing code may well work with just that change made.
 

toxicmouse

Senior Member
Added: And having just made the same mistake myself. Use -
SerIn ... b0

Not -

SerIn ... ( b0 )

Your existing code may well work with just that change made.
Hippy, thank you. This works perfectly! It was the parentheses causing the problem!
 
Top