Author Topic: Best communication protocol for multi-master communication  (Read 4462 times)

0 Members and 1 Guest are viewing this topic.

Offline danners430

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Best communication protocol for multi-master communication
« on: October 14, 2018, 09:02:30 pm »
Evening folks,

I'm designing a microcontroller based control system for a model railway. It'll control points and signals, and take feedback from track occupancy detectors and of course a user interface.

As all of these will be scattered around the layout, I've been trying to find a communication protocol which would be suitable - the obvious one is i2c, but it of course can't communicate over large distances without bus buffers. Those, I've found, wouldn't seem to work with true multi-master communication, as they split the signals into 4 unidirectional lines for transmission. The multi-master would be the best way I think to work, so that items such as block occupancy can be immediately transmitted to the control module without having to poll continuously.

So my question is this - what would be the best communication protocol in member's opinions? Is there a way to get i2c multi-master to work in a multi-drop configuration over long distances (up to 10-15m), or which other protocol would be recommended? Preferably one which can easily be implemented on many different MCUs :-)

Cheers in advance!

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 19924
  • Country: nl
    • NCT Developments
Re: Best communication protocol for multi-master communication
« Reply #1 on: October 14, 2018, 09:07:50 pm »
UART over RS485 or CAN are good candidates. If you use a text based UART protocol it will be easy to debug as well. OTOH you could use ethernet protocol over RS485 as well using a UART. There are several small IP stacks for use in microcontrollers but UDP would be sufficient. You can use libpcap to capture network traffic from your real ethernet network and bridge it (with some filtering) with the UART over RS485 ethernet network. I've build something like this over a decade ago.
« Last Edit: October 14, 2018, 09:09:58 pm by nctnico »
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline danners430

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Best communication protocol for multi-master communication
« Reply #2 on: October 14, 2018, 09:12:18 pm »
UART over RS485 or CAN are good candidates. If you use a text based UART protocol it will be easy to debug as well. OTOH you could use ethernet protocol over RS485 as well using a UART. There are several small IP stacks for use in microcontrollers but UDP would be sufficient. You can use libpcap to capture network traffic from your real ethernet network and bridge it (with some filtering) with the UART over RS485 ethernet network. I've build something like this over a decade ago.
RS485 sounds good - however, is there clash detection built in in the same way as i2c? I know CAN has it, but it's harder to find MCUs with it natively built in, so obviously I'd prefer 485 in that case

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 19924
  • Country: nl
    • NCT Developments
Re: Best communication protocol for multi-master communication
« Reply #3 on: October 14, 2018, 09:20:09 pm »
With anything else but CAN you'll have to implement the collission detection yourself. I solved that by reading the data back and verifying it against the data being send.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline danners430

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Best communication protocol for multi-master communication
« Reply #4 on: October 14, 2018, 09:21:19 pm »
With anything else but CAN you'll have to implement the collission detection yourself. I solved that by reading the data back and verifying it against the data being send.
That would seemingly work... I'll do some research and testing then :-)

Cheers!

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline ajb

  • Super Contributor
  • ***
  • Posts: 1797
  • Country: us
Re: Best communication protocol for multi-master communication
« Reply #5 on: October 14, 2018, 09:34:08 pm »
Do you actually need multimaster?  A polled system is likely to be simpler and easier to debug.  You can do things like global or group based polling to detect when a device needs attention to speed up response times if necessary. 

Note that in any system where collisions are expected, checksums or other validation methods are mandatory. 
 

Offline danners430

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Best communication protocol for multi-master communication
« Reply #6 on: October 14, 2018, 09:37:35 pm »
Do you actually need multimaster?  A polled system is likely to be simpler and easier to debug.  You can do things like global or group based polling to detect when a device needs attention to speed up response times if necessary. 

Note that in any system where collisions are expected, checksums or other validation methods are mandatory.
Well in theory collisions wouldn't occur at all if I used polling. The structure is reasonably simple - user interfaces, which interface only with the command module. This interfaces with one other module which carries out purely logic calculations, for the model railway interlocking. The command module also controls and takes input from all the various "actuators" around the layout.

How efficient would polling be, and how could it be implemented? I'm estimating that during a running session, I could have anything up to 4 track circuit status changes per second, plus of course user inputs. These all ideally need to be detected as quickly as possible, especially the track circuits.

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline ajb

  • Super Contributor
  • ***
  • Posts: 1797
  • Country: us
Re: Best communication protocol for multi-master communication
« Reply #7 on: October 14, 2018, 09:57:01 pm »
In a simple polling setup, the bus master would send a message to each device on the bus requesting its status.  The request message can be as little as two bytes: a 'get status' command, and a station address.  The response can be a couple of bytes that either reflect the complete state of a simple device, or that tell the controller whether or not the device requires further attention.  You could have a bit that indicates whether the device's status has changed since the last time, another bit that indicates if the device is operating normally or has an error, or whatever.  The response could even be variable length, it really depends on how much data a given device can or should supply.

If you have, say 8 bytes of poll/response, that amounts to about 80-100 bit times on a UART depending on parity/stop bits, so for 100 devices, a 1Mbd serial link would allow you to poll all devices at 100Hz.

If you need faster polling, you can do basic group polling, where the controller sends a message asking if any devices in a given group have any status change to report.  Each device that does then replies with its address.  If no devices have anything to report, the controller receives no response.  If exactly one device has something to report, the master will receive a valid message and will immediately know the address of the device that wants attention.  If multiple devices have status to report, then there will be a collision, the controller will receive an invalid message, and thereby know that more than one device wants attention.  At that point the master can either poll the entire group, or poll a subset of the group.  If your group poll message includes an address range you can even implement a binary search to find which individual devices have responded, but you probably won't have a large enough address space to warrant this.  (RDM uses this method to discover devices on a network, but there the address (UID) range is 48 bits, so it makes a lot more sense.)

Polling may not make sense for user inputs, it really depends on what kinds of inputs you have.  A button/light panel is going to be very different from a sophisticated GUI.
 

Offline danners430

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Best communication protocol for multi-master communication
« Reply #8 on: October 14, 2018, 10:02:03 pm »
The UI I'm trying to implement as a completely separate system, the aim being to have different types which all perform the same basic functions - in my case to emulate different real-world signalling panels.

I could always put them on a separate bus to the rest of the layout, and have the UI poll the control module for status updates, and send commands.

Thanks for the clarification... I suspect I may go with polling... Perhaps go back to i2c, since the communication will essentially be master to slave now anyway...

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3261
  • Country: lv
Re: Best communication protocol for multi-master communication
« Reply #9 on: October 14, 2018, 10:22:26 pm »
Thanks for the clarification... I suspect I may go with polling... Perhaps go back to i2c, since the communication will essentially be master to slave now anyway...

I2C is bad choice for your 10-15m application, it most likely will have reliability issues. Better just use suggested RS485.
 

Offline danners430

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Best communication protocol for multi-master communication
« Reply #10 on: October 14, 2018, 10:23:43 pm »
Thanks for the clarification... I suspect I may go with polling... Perhaps go back to i2c, since the communication will essentially be master to slave now anyway...

I2C is bad choice for your 10-15m application, it most likely will have reliability issues. Better just use suggested RS485.
The main reason I want to use i2c if possible, is that it's natively supported on umpteen different MCUs, whereas I don't think RS485 is... If I were to use PCA9600 bus buffers however, it should in theory work fine

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 19924
  • Country: nl
    • NCT Developments
Re: Best communication protocol for multi-master communication
« Reply #11 on: October 14, 2018, 10:29:30 pm »
RS485 is just as easy as I2C. With I2C you need to do polling anyhow. With RS485 you can use a text based protocol where a command and response are a single line of text (which ends with CR). This is extremely easy to test, debug and most importantly: to expand.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 5559
  • Country: fr
Re: Best communication protocol for multi-master communication
« Reply #12 on: October 14, 2018, 10:43:32 pm »
+1 for RS485. Besides, you can get much faster communication speeds, there's a lot of RS485 driver ICs over there that are well protected and you can use much longer wires than with I2C.

 

Offline ogden

  • Super Contributor
  • ***
  • Posts: 3261
  • Country: lv
Re: Best communication protocol for multi-master communication
« Reply #13 on: October 14, 2018, 10:48:20 pm »
The main reason I want to use i2c if possible, is that it's natively supported on umpteen different MCUs, whereas I don't think RS485 is...

To run RS485, nothing much is needed [for each node]: bus transceiver IC, UART or USART peripheral, one GPIO pin for tranceiver direction switch and small piece of CPU code for bus direction handling. The rest of the code is more or less similar to what you would do with I2C.
« Last Edit: October 14, 2018, 10:50:34 pm by ogden »
 

Offline danners430

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Best communication protocol for multi-master communication
« Reply #14 on: October 14, 2018, 10:50:47 pm »
So I did some research on RS-485, and while my brain now hurts (probably a result of that cider...), I think I have a basic understanding.

For the sake of simplicity, I'm guessing I could use a MAX485 to translate simple TTL to RS-485 signals? Useful, as most of the "actuators" in my setup will be basic PICAXE chips, simply because they're really easy to program, cheap and cheerful. However, they only natively accept TTL, and not RS-485... Could still work, but I'd be bit-banging.

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: gb
Re: Best communication protocol for multi-master communication
« Reply #15 on: October 15, 2018, 12:22:09 am »
For the sake of simplicity, I'm guessing I could use a MAX485 to translate simple TTL to RS-485 signals?
That's pretty much it in a nutshell.

There are other alternative parts to Maxim, which I find tend to be rather expensive. e.g. I've used the SN75176 from TI in one of my projects.

At the end of the day they all achieve the same thing and should be interoperable.
 

Offline mrpackethead

  • Super Contributor
  • ***
  • Posts: 2831
  • Country: nz
  • D Size Cell
Re: Best communication protocol for multi-master communication
« Reply #16 on: October 15, 2018, 12:44:05 am »
ethernet will be easy. If you do POE you can even power up your devices all over the place, with a single cable.   Ethernet is cheap to implement, and you get hte bonus its isolated.
On a quest to find increasingly complicated ways to blink things
 

Offline ehughes

  • Frequent Contributor
  • **
  • Posts: 402
  • Country: us
Re: Best communication protocol for multi-master communication
« Reply #17 on: October 15, 2018, 12:48:26 am »
https://www.nxp.com/docs/en/data-sheet/LPC11CX2_CX4.pdf

48 pin package,    CAN transceivers built it.    There is also a driver in ROM for CAN functions.   As soon as you have to do collision detection,   go with CAN.   It saves a lot of hassle.    IF you need higher data rate,   CAN FD is very nice.   
 

Offline lwatts666

  • Supporter
  • ****
  • Posts: 66
  • Country: au
Re: Best communication protocol for multi-master communication
« Reply #18 on: October 15, 2018, 01:05:49 am »
CAN bus is nice, since collision detection and node prioritization is done at the hardware level. As others have said, not all micros have the requisite hardware support.

RS485 with a simple token ring protocol would fit the bill, but fully fault tolerant token rings are difficult to implement.

If physical node failure tolerance is not a major issue, then a simple sequential master protocol over RS485 can be used. Data packets consists of a packet header containing the source node address, the data payload which may be empty, and a tail, with checksum if required.  Node-0 sees no comms for x milliseconds, so sends out its packet. Node-1 sees tail of Node-0's packet, so sends it packet. Node 2 sees tail of Node-1's packet, so sends it packet, and so on. When last node send its data, there is no more comms, so Node-0 starts again. If a packet is corrupt, all nodes shut up, and Node-0 starts again. Major failure mode is where a physical Node fails in the middle of the address range, which will result in all higher addressed nodes never communicating. Failure of Node-0 means nothing communicates, but lack of response make it easy to troubleshoot...

 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 7633
  • Country: us
Re: Best communication protocol for multi-master communication
« Reply #19 on: October 15, 2018, 02:23:38 am »
Here is a multi-master protocol layered over RS485.  It handles collisions by listening while talking.

http://www.bdmicro.com/code/robin/
 

Offline laneboysrc

  • Contributor
  • Posts: 26
  • Country: sg
    • LANE Boys RC - radio control related electronics
Re: Best communication protocol for multi-master communication
« Reply #20 on: October 15, 2018, 02:38:14 am »
Since this is for a model railway have a look at Lenz's Xpressent protocol. It is based on RS485.

Marketing blurb: http://lenzusa.com/1newsite1/XpressnetFAQ.html
Technical spec: http://lenzusa.com/1newsite1/Manuals.html#xpressnet

Even if your use-case is different you may still get some inspiration out of it.
 

Offline ehughes

  • Frequent Contributor
  • **
  • Posts: 402
  • Country: us
Re: Best communication protocol for multi-master communication
« Reply #21 on: October 15, 2018, 03:08:29 am »
Sorry to hijack this thread but I have always dreamed of a model rail road around the office.   I want an o guaged size to go between desks and make stops (interoffice mail!)        Where is the cheapest source for track?   It seems to be quite expensive!
 

Offline danners430

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Best communication protocol for multi-master communication
« Reply #22 on: October 15, 2018, 06:21:54 am »
Hey guys,

Sorry - fell asleep :D

From looking at everything, I think I'll go with RS-485 with MAX485s or equivalent. For control, I'll simply have the master polling in a single master setup. For the communication between the control module and the user interface, I'll probably use dual unidirectional TTL lines, as there's no need to poll - just send commands to one another.

I'll take a look at Expressnet, see what that comes up with :-)

Cheers for the help folks!

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline Brianf

  • Newbie
  • Posts: 4
  • Country: gb
Re: Best communication protocol for multi-master communication
« Reply #23 on: October 15, 2018, 07:39:38 am »
As you are in the UK, you could do worse than look at what MERG have done with CANBUS.
 

Offline danners430

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Best communication protocol for multi-master communication
« Reply #24 on: October 15, 2018, 07:56:50 am »
As you are in the UK, you could do worse than look at what MERG have done with CANBUS.
Aye, I've had a look at MERG... But it's just not as flexible as I'd like - as a maker, I love making things work myself, and I've just not found that flexibility with MERG equipment

Sent from my ONEPLUS A3003 using Tapatalk

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf