Communications with confirmation

rjandsam

Member
Hi Guys,
I was just after some pointers with regards to communications over a serial link and wondered if the following would be suffice for a wired or wireless setup?
the main code has yet to be written I am more interested in the data link first any advice on improving things is much appreciated.
The modules I want to create are all 14m2 Masters talking to a single Picaxe 28x2 slave receiver that is displaying the data that they are transmitting, its just I don't want the receiver to miss anything.

Rich
b.2=busy line
b.0=serial out
b.1=serial in
c.0=switch input for test

main:
low b.2
if pinc.0=1 then let b10="A" let b17="Z" reverse b.2 goto serialtx
endif
goto main

serialtx:
if pinb.2=1 then serialtx
high b.2
let b19=b19+1
if b19=6 then let b19=0 let bit0=1 let b18=0 goto main
endif
serout b.0,t19200_32,("UUUUUTEST",b10,b11,b12,b13,b14,b15,b16,b17)
ack:
let bit0=0
let b18=b18+1
if b18=10 then let b18=0 goto serialtx
endif
serin [200,ack], b.1,t19200_32,("TESTACK") 'rec
let bit0=1
goto main
 

rossko57

Senior Member
How does "busy line" work? It might be worth looking at how commercial, robust systems work; like Modbus and Ethernet. Whats the communication medium, out of interest?
 

hippy

Technical Support
Staff member
The code is very complicated and obscure so a description of how it is meant to work would help and perhaps remove extraneous commands; assigning values to bit0 seems redundant.

What are the purposes of b18 and b19 use ? It seems to me that b18 would never increment to 10 as b19 reaching 6 would reset b19 to zero first.

How the hardware interaction on B.2 works, what is actually connected to that, would also help.

Note that what works for a wired system will likely need to be different for a wireless system.
 

rjandsam

Member
Hi Hippy/Rossko57
it is just code I came up with to test simple communications between 10 14m2 masters and a 28x2 slave nothing exists at the moment other than this code for the comms.
The busy line works by going high when a 14m2 master module is transmitting so that the others cannot transmit at the same time so all 14m2 modules will receive a high on b.2 until it is clear to send.
once it has sent out all of its variable data it drops into ack: waiting for the receiver to acknowledge receipt if this acknowledge does not return it times out incrementing b18 once b18 =10 it returns back to serialtx to try and resend the data another 5 times until it gives up and returns to the main code.
bit0 is set as a flag to show a successful transmission that would be used later in the main code to detect a failed transmission If set to 0 hope I have explained this ok.

Rich
 
Last edited:

hippy

Technical Support
Staff member
Unfortunately it is not possible to use a single digital busy. That signal needs to be able to identify access as by "none", "one" or "two or more". A digital signal will only allow identifying "none" and "one or more". A digital "none or one" and "two or more" is not achievable with a single digital I/O line.

You most likely need to use a digital output to indicate seeking and taking access and an analogue input to monitor how many have access. A proposed example for that can be found here -

http://www.picaxeforum.co.uk/showthread.php?16523-2-picaxes-and-one-memory-chip&p=147137&viewfull=1#post147137

It is probably best to start with multiple slaves which simply send their serial without waiting for acknowledgement and no care whether their data is received or not. Get the arbitration working before anything else.
 

rjandsam

Member
Thank you for the replies, I will try what you have suggested Hippy by not acknowledging a receive and grow from that point into using an adc and digital output as suggested.

Thank you
Rich
 

Goeytex

Senior Member
Hi Rich,

Good advise from hippy, but I might add, that as was already suggested, what works with a wired setup will not necessarily work with a wireless setup. Starting with a wired setup is good, but if the final application is wireless a lot will have to be changed, modified.

As far as a wired goes, how it will perform with serout / serin depends largely upon the distance between the transmitters & receiver. You will also need to consider the serial bus. You cannot simply tie all 10 of the serial out pins together, as this would result in multiple shorted outputs. You could possibly "OR" the serial outputs or even carefully toggle pins as inputs / outputs to get around this. If the distance is not too far TTL serin / serout can be used. However for longer distances a more robust method will be needed. What distance will you need ?

Perhaps if you tell us what distances you expect and whether the final application will be wireless or wired, that better & more specific help can be provided.
 

rossko57

Senior Member
If you can turn your project about to a single master polling many slaves, all your headaches will go away.

Else, as Hippy says, a simple "busy" signal cannot prevent simultaneous access. So basically it is useless, you might consider abandoning it altogether. You could look up how CSMA works, but that does require a transmitting device to also "listen" to the line or radio or light beam or whatever you are using to see that what is expected to be sent really is sent. CSMA is almost the opposite approach, assume clashes will be inevitable but have a robust way to deal with them.

Even with a tri- or more state "busy" line there is a risk of bad things happening between checks. Whatever scheme you ultimately use is almost certain to require at least simple checksums to detect glitches and corruption. Study of various protocols will show you the means to do that. Having got some error detection, you'd no doubt have a re-try strategy too. With reliable error detection and retry in place you really don't need any busy line at all ....

Choosing the best path depends a lot on your application, how much data transfer is going on, how many stations, risks of interference or signal attenuation, timing (you might be talking km here), blah.
 

rjandsam

Member
Great advice all of you thank you, what if I used max485 chips would this be an easier solution? The distance between all devices would be no greater than 30 metres.
The 10 devices that are masters would be sending about 10 variables worth of data around about the same time as each other every couple of mins or so.
I think I will study a few protocols tomorrow to gain a better understanding as suggested.

Rich
 

g6ejd

Senior Member
Are you sending data (0-255) or text (ASCII), if the latter, then use a byte value as your handshake. e.g. test, EOL, text, EOL where EOL is say 0 or 255 or any unused value. For the former, you could use a sequence for handshaking on the presumption that getting e.g. 00,01,02 in sequence is very rare.
 
Top