Author Topic: MODbus library and which microcontroller  (Read 3308 times)

0 Members and 1 Guest are viewing this topic.

Offline Suze1990Topic starter

  • Newbie
  • Posts: 2
  • Country: gb
MODbus library and which microcontroller
« on: June 06, 2016, 08:30:18 pm »
Hi all,

I have a little knowledge of microcontrollers mainly messing about with Arduino, as well as the MSP430 and Tiva C from TI.

Looking into using MODbus for a small home automation project and wondering what libraries are available andfor which microcontrollers?  I have mad e a few searches but found limited direct information.  Alternatively I am thinking about CAB bus on the Tiva C as there is a library for this available.

Any thoughts, links and advice would be appreciated 😀

Suze
 

Offline Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: MODbus library and which microcontroller
« Reply #1 on: June 07, 2016, 09:57:42 am »
Why would you use an industrial bus for your hobbie project UNLESS you have a lot of these industrial devices lying around?
If you have no devices, don't start with it would be my advice, those devices cost serious money for almost nothing except they are fully compliant and tested with that bus/protocol.
 
If you want to build your own devices you can create your own protocol with for instance RS485 and it will be much more easy and faster up and running.
You could look at modbus for inspiration and simplify it, or look at another hobbie version that was created by Elektor called the Elektor Home Bus a few years back (2011 or 2012 i believe).
They even created a lot of peripherals for it.
That would be my advice, make your own protocol or use the Elektor's homebus protocol if you would like to simply add devices that other people build.

First make a list of requirements for your protocol:
some things to think about
- multimaster?
- collision resistant or taken care of with a seperate control line or in the sw protocol
- error correction codes on the command
- how many bytes,
- how many addresses (total of devices that can be addressed)
- list of commands (eg list of functionality/devices)
etc.

 

Offline gmb42

  • Frequent Contributor
  • **
  • Posts: 294
  • Country: gb
Re: MODbus library and which microcontroller
« Reply #2 on: June 07, 2016, 11:18:16 am »
Why would you use an industrial bus for your hobbie project UNLESS you have a lot of these industrial devices lying around?
If you have no devices, don't start with it would be my advice, those devices cost serious money for almost nothing except they are fully compliant and tested with that bus/protocol.
 
If you want to build your own devices you can create your own protocol with for instance RS485 and it will be much more easy and faster up and running.
You could look at modbus for inspiration and simplify it, or look at another hobbie version that was created by Elektor called the Elektor Home Bus a few years back (2011 or 2012 i believe).
They even created a lot of peripherals for it.
That would be my advice, make your own protocol or use the Elektor's homebus protocol if you would like to simply add devices that other people build.

First make a list of requirements for your protocol:
some things to think about
- multimaster?
- collision resistant or taken care of with a seperate control line or in the sw protocol
- error correction codes on the command
- how many bytes,
- how many addresses (total of devices that can be addressed)
- list of commands (eg list of functionality/devices)
etc.
- security, i.e. encryption and authentication, neither of which modbus has.

I agree with Kjelt, unless you happen to have a lot of Modbus PLC's lying around don't bother with modbus.
 

Offline Eternauta

  • Contributor
  • Posts: 41
  • Country: it
Re: MODbus library and which microcontroller
« Reply #3 on: June 07, 2016, 11:33:46 am »
About the Modbus library:
http://www.freemodbus.org/
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26896
  • Country: nl
    • NCT Developments
Re: MODbus library and which microcontroller
« Reply #4 on: June 07, 2016, 11:57:32 am »
If you want to build your own devices you can create your own protocol with for instance RS485 and it will be much more easy and faster up and running.
I doubt it. Coming up with a protocol which is fault tolerant and reliable is very hard! When communication is required between devices you are basically building a distributed system and that has many potential problems like race conditions, synchronisation and fault handling. If you can start with a (simple) protocol which already does this then you are already half way there.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline BradC

  • Super Contributor
  • ***
  • Posts: 2106
  • Country: au
Re: MODbus library and which microcontroller
« Reply #5 on: June 07, 2016, 12:01:28 pm »
Whilst I mostly agree with the other replies I must also say Modbus is pretty easy to implement, spectacularly documented and with stacks of easily available validation tools.

No security though.
 

Offline Suze1990Topic starter

  • Newbie
  • Posts: 2
  • Country: gb
Re: MODbus library and which microcontroller
« Reply #6 on: June 07, 2016, 08:07:54 pm »
Hi all,

Firstly thanks for all the comments and insights, very useful and maybe I needed to look at this from a different perspective and rephrase my question!

I can see the point about the MOD bus being unnecessary for a home application like mine, I am also driven by the idea that I wanted to learn more about the protocol as well.  However it sounds like I am better using an easier protocol for the home system and will look at protocols better supported by the Tiva C in this case.

Now as I said I have an interest in trying to learn a bit more about MOD bus, is there a particular microcontroller that someone can recommend that would be a good hardware platform for this purpose?  (I would say the MSP430G series devices are not suitable for example, as the USI and USCI on these devices means poor internal peripheral hardware support).

Thanks again,

Suze
 

Offline sca

  • Regular Contributor
  • *
  • Posts: 68
Re: MODbus library and which microcontroller
« Reply #7 on: June 07, 2016, 08:20:17 pm »
 Various STM32 micros have a Receive Time Out interrupt which makes end of frame / error detection really neat, but you can do it on almost anything with a reasonable UART and a timer.

sca
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 26896
  • Country: nl
    • NCT Developments
Re: MODbus library and which microcontroller
« Reply #8 on: June 07, 2016, 09:19:55 pm »
More food for thought before you begin:
IMHO one of the important things in home automation is security. Good security is based on authentification, authorisation and accounting. This means you need to be able to tell whether a message is real / legitimate, whether the sender is allowed to perform the action in the message and keep a log of the messages so you can figure out what happened afterwards in case of problems. Note that this doesn't mean encryption perse; actually a well designed system does not need to depend on encrypting the messages.

So the first step is not choosing a protocol but choosing how the system will work at a higher level in order to make it secure.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Kjelt

  • Super Contributor
  • ***
  • Posts: 6460
  • Country: nl
Re: MODbus library and which microcontroller
« Reply #9 on: June 08, 2016, 09:09:58 am »
Concerning the home automation security this largely depends on the choosen protocols and interfaces. If you use for instance a RS485 network for all your devices then the point where you need to make sure the security is top notch is at the gateway between the internet and that network.
The network itself can be unsecured unless you want to protect against people getting into your house and adding their own spy-devices which is probably a step too far.
If for instance you don't want to control your home from outside the house than you even have less security requirements, and reporting out through email or a webserver is not a big problem as long as there is no control from outside allowed. But a good point to take a look at your requirements if and where security precautions are needed.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf