MODbus library and which microcontroller - Page 1
Forum section: electronics / general

author: Suze1990
author_rank: Newbie
timestamp: June 06, 2016, 08:30:18 pm
content: 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

author: Kjelt
author_rank: Super Contributor
timestamp: June 07, 2016, 09:57:42 am
content: 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.

author: gmb42
author_rank: Frequent Contributor
timestamp: June 07, 2016, 11:18:16 am
content: Quote from: Kjelt on June 07, 2016, 09:57:42 am- 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.

author: Eternauta
author_rank: Contributor
timestamp: June 07, 2016, 11:33:46 am
content: About the Modbus library:http://www.freemodbus.org/

author: nctnico
author_rank: Super Contributor
timestamp: June 07, 2016, 11:57:32 am
content: Quote from: Kjelt on June 07, 2016, 09:57:42 amI 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.

author: BradC
author_rank: Super Contributor
timestamp: June 07, 2016, 12:01:28 pm
content: 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.

author: Suze1990
author_rank: Newbie
timestamp: June 07, 2016, 08:07:54 pm
content: 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

author: sca
author_rank: Regular Contributor
timestamp: June 07, 2016, 08:20:17 pm
content: 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

author: nctnico
author_rank: Super Contributor
timestamp: June 07, 2016, 09:19:55 pm
content: 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.

author: Kjelt
author_rank: Super Contributor
timestamp: June 08, 2016, 09:09:58 am
content: 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.