What's that? Did you send something?

Andrew Cowan

Senior Member
I'm having some problems with serial communication.

The (largely simplified) setup is the output of a 20M outputting serial data at N4800 baud. This data is then received by a 28X2.

The code running on the 20M is: serout pin,N4800,(b1,b2,b3,b4,b5)
And the code on the 28X2: serin pin,N4800,b1,b2,b3,b4,b5

However, the code in the 28X2 would always get stuck at the serin - it seemed to never receive all the data.

Eventually I found the problem - this was an initial test, and all the variables being transmitted were zero. Changing the variables to other numbers made the system work.

I assumed that the problem was that 0 (%00000000) means the data line never goes high, thus the 28X2 never realises data is being sent. However, the manual refers to stop bits (and I presume there is a start bit) - should this not tell the 28X2 there is data? Is it possible to transfer a string of zeros via serial? The values of the variables could be anything, so it needs to be able to cope with zero.

Any ideas of why this didn't work?

Many thanks

Andrew
 

hippy

Technical Support
Staff member
Very odd and it should work. The Start bit is always the opposite of the idle state and sent before the data bits which is how the PICAXE ( and any serial device ) knows data is arriving even when all data bits are the same as the idle state.

I'll take a look at the same setup.
 

hippy

Technical Support
Staff member
Works okay for me ...

#Picaxe 20M
Do
SerOut 0, N4800, ( 1, 2, 3, 4, 5 ) : Pause 1000
SerOut 0, N4800, ( 0, 0, 0, 0, 0 ) : Pause 1000
SerOut 0, N4800, ( b0, b1, b2, b3, b4 ) : Pause 1000
Loop

#Picaxe 28X2
#No_Table
#Terminal 9600
Do
SerIn C.0, N4800, b0, b1, b2, b3, b4
SerTxd( #b0, #b1, #b2, #b3, #b4, CR, LF )
Loop

That shows -

12345
00000
00000
12345 etc
 

Andrew Cowan

Senior Member
Very odd. My serial network is quite large (the output is connected via a 1N4148 diode). There are then six other PICAXEs connected along it (via diodes on the outputs and direct to inputs). It must be due to some electrical factor of the network.

Am I right in thinking that SerTxd( b0, b1, b2, b3, b4, CR, LF ) will show nothing if all the variables are zero?

Andrew
 

BeanieBots

Moderator
Set your terminal to show unprintable characters to see the raw data.
Silly question, but have you got a resistor on your 'diode OR' arrangement?
 

Andrew Cowan

Senior Member
Set your terminal to show unprintable characters to see the raw data.
- Good idea. I'm currently using either PE's built in one or a serial port sniffer - what's everyone's favorite terminal? Hyperterm?
Silly question, but have you got a resistor on your 'diode OR' arrangement?
- Do you mean the pull-down? If you mean a different resistor then no - should I have one?

A
 

hippy

Technical Support
Staff member
A pull-down will almost certainly help and may be necessary. BB beat me to that suggestion.
 

Andrew Cowan

Senior Member
I think one of my boards has a 10K pulldown on it - other than that all the output connections are straight through the 1N4148.

A
 

BeanieBots

Moderator
Double check that you DO have a pull-down.
Double check polarity of all diodes.
Double check 0v connection between boards.

A simple diode drop should not cause any issues. It has to be a 'silly'
 

Andrew Cowan

Senior Member
Will do - thanks for the help.

I've checked all the diodes, and the boards all share a 5V supply, but I'm not sure about the pulldown. Thanks again.
 

moxhamj

New Member
Having one node the 'server' and putting the pulldown on that node works as you would never not have that node, but if you have a 'peer to peer' network and you happen to pull out the node that has the pulldown then the whole network crashes. In that scenario more formal logic OR gates, possibly with input protection, might be better.

Having said that, the diode 'or' might also be a red herring. There will always be a start bit and a stop bit and they are opposite polarity so sending a zero is certainly not the same as just having the line low (or high). http://www.beyondlogic.org/serial/serial1.htm#40

If this is only on startup and only when sending zeros, I wonder if there is a glitch on startup and this is being interpreted as the first start bit then the serin reads the first byte but gets stuck when no stop bit arrives and just hangs?

I'd be inclined to add the header 'ABC' to all packets as it doesn't cost much in terms of speed and it kicks serin out of any hangs and will resynch the packets.

As for tracing data, I like serial port sniffer programs, then it doesn't matter what terminal program you are running.
 
Top