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

0 Members and 1 Guest are viewing this topic.

Offline danners430

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Best communication protocol for multi-master communication
« Reply #50 on: October 16, 2018, 02:32:28 pm »
Aye, but I have plans for the rest of the rest of the twisted pairs *evil cackle*

Nah, I'm gonna use the rest of the cable for future-proofing - allows me to use a second protocol in the future, or even use ethernet as well as CAN. Certainly in the future I intent to connect the layout to a computer, and eventually as an IoT device to my local network. And since that only requires 2 twisted pairs, I might as well

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 2057
  • Country: fi
Re: Best communication protocol for multi-master communication
« Reply #51 on: October 16, 2018, 02:44:31 pm »
CAN is just fine with quite a lot of line impedance mismatch, CAT5 is not only acceptable, but actually very good. CAN is slow and has edge rate control, hence the impedance matching on the cable, while theoretically still valid, bears little significance unless you are aiming for very long links (tens of meters). This is by design.

Framing is worth a consideration in any message system. UART (what you would use through RS485) naturally delimits at 8 bits. CAN frames at 8 bytes (64 bits) max. Properly hardware-implemented SPI has practically no limit, so the framing is SPI's strong point - although it's not usually properly hardware-implemented, and any multi-master kludges suck on SPI, so that's about it...

In any case, it's always a bit easier when you can limit the message size below the framing length. This way, you don't need to know where your message starts and where it ends, you don't need state, and your parser is the easiest thing on the planet. In UART, that's seldom possible (although sometimes it is, you can fit quite a lot of commands in 8 bits for example!), but the 8 bytes in CAN is often enough to do quite a lot, especially since you can utilize the wide address space as your "header", to signify different commands / subsystems / tasks / message types / whatever, leaving more of that 8 bytes for the actual payload data!

Hardware-wise, RS422/RS485 and CAN are both very simple, robust, cheap, and easy to deploy. Whichever is just fine. Both would also be somewhat cheaper solutions than Ethernet; especially if you consider the software complexity. Ethernet becomes an attractive off-the-shelf solution when you need isolation, or high datarates beyond a few Mbps.
 

Offline danners430

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Best communication protocol for multi-master communication
« Reply #52 on: October 16, 2018, 02:46:56 pm »
All sounds good - I mentioned ethernet simply as a future project, which is the reason why I'm using CAT5 cable.

I'm having a look round the internet, however, and I'm struggling to find information on how to implement CAN on a microcontroller - in my case a PIC. Can anyone point me to a good tutorial?

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 1805
  • Country: ca
Re: Best communication protocol for multi-master communication
« Reply #53 on: October 16, 2018, 03:07:20 pm »
I'm having a look round the internet, however, and I'm struggling to find information on how to implement CAN on a microcontroller - in my case a PIC. Can anyone point me to a good tutorial?

CAN modules are different. For peculiarities, it's best to read data sheets and app notes for your particular MCU.

If you want to connect your CAN bus to the PC or to the Internet in the future, you can just add a node to your CAN bus for communication purposes - USB, wired Ethernet, Wi-Fi, Bluetooth, whatever - or several of them. No need for special provisions now.
 

Offline danners430

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Best communication protocol for multi-master communication
« Reply #54 on: October 16, 2018, 03:36:24 pm »
I've had a look at the datasheet, and can't find anything useful for me... It's a PIC18F25, which has a CAN module built in.

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 2057
  • Country: fi
Re: Best communication protocol for multi-master communication
« Reply #55 on: October 16, 2018, 03:53:51 pm »
The MCU manual should explain everything you need to know. If not, you are either looking at the wrong manual, or have an unspecified microcontroller, and should change to something that has documentation (or reverse-engineer by trial&error).

Sometimes it's just called "datasheet", but sometimes it's called "reference manual". You need it anyway when developing for a microcontroller.

The CAN peripherals in MCUs tend to be fairly easy. You configure a few filters you can use to accept/ignore certain CAN IDs, and poll some mailbox status bits, or get an interrupt when a message arrives in the buffer.
 

Offline danners430

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Best communication protocol for multi-master communication
« Reply #56 on: October 16, 2018, 03:55:30 pm »
The main issue with the PICs is that they're generally programmed in C using a proprietary IDE... So it's really info on how to program them in C I'm after. And yes, I've looked up specifically for the IDE, MPLAB X, and haven't as yet found anything. But obviously I'm still looking.

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 2057
  • Country: fi
Re: Best communication protocol for multi-master communication
« Reply #57 on: October 16, 2018, 04:11:28 pm »
Oh, you are going to have some learning curve right there. Are you in a hurry? If not, I suggest, take your time. Start small, do your first LED blinker, try to use a timer peripheral to PWM the LED, then do some simple UART thing. Then I think you'll understand the documentation and the C language better and can take the CAN job. It's worth it.

About the PIC C compiler being proprietary, yeah, that kinda sucks, and there is no way around it. If this bothers you, you need to look at something else.
 

Offline danners430

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Best communication protocol for multi-master communication
« Reply #58 on: October 16, 2018, 04:14:14 pm »
I'm actually already slightly used to using C, not much but I know the basics. But I see what you mean :-) PICs are new to me, I've only worked with other micros before. I'll get started :-)

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline technix

  • Super Contributor
  • ***
  • Posts: 3219
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: Best communication protocol for multi-master communication
« Reply #59 on: October 16, 2018, 05:52:07 pm »
Pulling back in topic here, one idea I have is to run UART over CAN PHY, implement CSMA/CD and some kind of collision recovery.
 

Offline danners430

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Best communication protocol for multi-master communication
« Reply #60 on: October 16, 2018, 05:53:57 pm »
Pulling back in topic here, one idea I have is to run UART over CAN PHY, implement CSMA/CD and some kind of collision recovery.
Sorry... Could you repeat that in English? [emoji23]

I'm afraid you've lost me completely!

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline technix

  • Super Contributor
  • ***
  • Posts: 3219
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: Best communication protocol for multi-master communication
« Reply #61 on: October 16, 2018, 06:04:26 pm »
Pulling back in topic here, one idea I have is to run UART over CAN PHY, implement CSMA/CD and some kind of collision recovery.
Sorry... Could you repeat that in English? [emoji23]

I'm afraid you've lost me completely!

Sent from my ONEPLUS A3003 using Tapatalk
I believe you understand the OSI network model right? Here in this stack the physical layer is firmly defined and the data link layer is half defined. The physical layer uses CAN's electrical characteristics and signalling, but uses UART as its line code instead of CAN's own. The data link layer doesn't have a complete protocol definition yet, however the protocol need to implement the CSMA/CD algorithm to detect collision, and must be able to handle collision gracefully.

Not using CAN's line code and protocol stack while keeping its signalling allows you to dodge the cost and complexity of CAN hardware, while not breaking the collision detection feature.
 

Offline danners430

  • Regular Contributor
  • *
  • Posts: 137
  • Country: gb
  • Good at overcomplication
Re: Best communication protocol for multi-master communication
« Reply #62 on: October 16, 2018, 06:06:44 pm »
TBH, what advantage would it give? As far as I can tell I'm gonna have to learn a whole lot anyway, and the MCUs I'm looking at support CAN natively - I'm sure once I've done some learning I can find a library or method to easily program and use full CAN

Sent from my ONEPLUS A3003 using Tapatalk

 

Offline technix

  • Super Contributor
  • ***
  • Posts: 3219
  • Country: cn
  • From Shanghai With Love
    • My Untitled Blog
Re: Best communication protocol for multi-master communication
« Reply #63 on: October 16, 2018, 06:14:47 pm »
TBH, what advantage would it give? As far as I can tell I'm gonna have to learn a whole lot anyway, and the MCUs I'm looking at support CAN natively - I'm sure once I've done some learning I can find a library or method to easily program and use full CAN

Sent from my ONEPLUS A3003 using Tapatalk
The biggest point of UART over CAN PHY is dodging the CAN harware. Sure your current MCU has CAN, but not all MCU has it and it is usually associated with a price premium. For my projects I was using UART over CAN with STM32F030F4P6, its Chinese workalike GD32F130F8P6, or even IAP15W4K61S4. Those are all extremely cheap chips that does not have CAN.

It is also a crucial learning experience as CSMA/CD is one of the most basic multiple access protocols used in networking, and unlike its sibling CSMA/CA (as used in Wi-Fi of all things) it allows true peer to peer network where anyone can start speaking politely at any moment on a shared media.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf