Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 17:44 02 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Modbus Protocol in MMBasic

     Page 2 of 2    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 01:55pm 21 Jun 2018
Copy link to clipboard 
Print this post

Can you also confirm the bit pattern for modbus so I can test. Is it:

start bit, 8 data bits, parity bit, stop bit?

Is parity even or odd? or do you prefer 2 stop bits instead of parity?
 
goc30

Guru

Joined: 12/04/2017
Location: France
Posts: 435
Posted: 02:00pm 21 Jun 2018
Copy link to clipboard 
Print this post

its classic, 9600,8,n,1
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 02:16pm 21 Jun 2018
Copy link to clipboard 
Print this post

I'm confused - is this wrong?

  Quote  Modbus Com Port Settings
ASCII
Start Bit = 1
Data Bits=7
If Parity is even or off then Stop Bits = 1
If Parity is none then Stop Bits = 2

RTU
Start Bit = 1
Data Bits=8
If Parity is even or off then Stop Bits = 1
If Parity is none then Stop Bits = 2
 
goc30

Guru

Joined: 12/04/2017
Location: France
Posts: 435
Posted: 02:24pm 21 Jun 2018
Copy link to clipboard 
Print this post

I use RTU mode (binary frames with transmitting zero value)
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 02:35pm 21 Jun 2018
Copy link to clipboard 
Print this post

Hi Peter,

No it's not wrong but I have never seen the ASCII version used. I've never seen the parity bit used either. Not sure about the number of stop bits though. I don't think it matters.

I confess that I don't understand the interrupt problem but will continue my attempts to build a Modbus master and slave(s) with the MM2.

Bill
Keep safe. Live long and prosper.
 
goc30

Guru

Joined: 12/04/2017
Location: France
Posts: 435
Posted: 02:48pm 21 Jun 2018
Copy link to clipboard 
Print this post

  Turbo46 said   Hi Peter,


I confess that I don't understand the interrupt problem but will continue my attempts to build a Modbus master and slave(s) with the MM2.

Bill


this function is used for real-time process. if you work in polling mode, you spend time to wait (wait to receive a char, or wait taht sender has finish to send a char). In Modbus protocole, time-out is very important. It is used to begin master frame or to make error flags, etc..
second point: if you work in polling mode, you cann't use an other COM port also in polling mode.

In my appli, i need the "1sec signal" from GPS with 1 millsec precision. In polling mode it is impossible (in racing appli, you have 1 GPS on start line, and 1 GPS in finish line)
 
Azure

Guru

Joined: 09/11/2017
Location: Australia
Posts: 446
Posted: 03:08pm 21 Jun 2018
Copy link to clipboard 
Print this post

Here is a link to the current Modbus Serial Standard

Here is an extract on the serial protocol (there are some illustrations in the pdf):
  Quote  The format ( 11 bits ) for each byte in RTU mode is :
Coding System:
8–bit binary Bits per Byte:
1 start bit 8 data bits, least significant bit sent first 1 bit for parity completion 1 stop bit

Even parity is required, other modes ( odd parity, no parity ) may also be used.

In order to ensure a maximum compatibility with other products, it is recommended to support also No parity mode.

The default parity mode must be even parity.

Remark : the use of no parity requires 2 stop bits.

How Characters are Transmitted Serially :
Each character or byte is sent in this order (left to right): Least Significant Bit (LSB) . . . Most Significant Bit (MSB)

Devices may accept by configuration either Even, Odd, or No Parity checking.

If No Parity is implemented, an additional stop bit is transmitted to fill out the character frame to a full 11-bit asynchronous character :
 
goc30

Guru

Joined: 12/04/2017
Location: France
Posts: 435
Posted: 04:00pm 21 Jun 2018
Copy link to clipboard 
Print this post

Hi Azure

With CRC16 (and short time-out), it is not necessary to add an odd/even bitEdited by goc30 2018-06-23
 
Azure

Guru

Joined: 09/11/2017
Location: Australia
Posts: 446
Posted: 04:27pm 21 Jun 2018
Copy link to clipboard 
Print this post

I was only providing a reference to the official Modbus serial protocol. It is linked directly from the Modbus website and is the new specification, there is an older specification for legacy purposes.
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1667
Posted: 09:21pm 21 Jun 2018
Copy link to clipboard 
Print this post

Posted this a few days back.

It would essentially be a Modbus RTU master polling 3 devices using 2 different requests.

Phil.Edited by Phil23 2018-06-23
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 11:18am 23 Jun 2018
Copy link to clipboard 
Print this post

Hi All,

Does anyone know of a good Modbus master program for the PC? Hopefully a free one.

Thanks
Bill
Keep safe. Live long and prosper.
 
goc30

Guru

Joined: 12/04/2017
Location: France
Posts: 435
Posted: 12:50pm 23 Jun 2018
Copy link to clipboard 
Print this post

hi Bill

  Turbo46 said   Hi All,

Does anyone know of a good Modbus master program for the PC? Hopefully a free one.

Thanks
Bill


Modbus is only a communication protocol and not a complete application, so first you have to know what you want to do with, then choose a prog language, finally know the device (s) you want to connect to the PC and using MODBUS protocol.
if the device is an RTU or any "end user" thing, then you have to see with the manufacturer who usually offers a MODBUS driver for PC. So we need more precisionEdited by goc30 2018-06-24
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1427
Posted: 01:23pm 23 Jun 2018
Copy link to clipboard 
Print this post

  Turbo46 said   Hi All,

Does anyone know of a good Modbus master program for the PC? Hopefully a free one.

Thanks
Bill


http://qmodbus.sourceforge.net/
Micromites and Maximites! - Beginning Maximite
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 01:37am 24 Jun 2018
Copy link to clipboard 
Print this post

Thanks CircuitGiszmos,
I'll give it a go. Have you used it?

@goc30: I wish to make a Modbus Slave/RTU using an MM2, test it thoroughly with a PC Modbus master and then make a Modbus master using another MM2 or a Maximite. They will comply with the 'Modbus Serial Standard' as in the link supplied by Azure above. The RTU will have Digital Outputs, Digital Inputs and Analogue Outputs. I am aware for your need for a "transmit buffer empty" interrupt, if I hit that problem I will find a way around it.

Regards,
Bill

Keep safe. Live long and prosper.
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1427
Posted: 05:14pm 24 Jun 2018
Copy link to clipboard 
Print this post

Yes I have used it. Great for initial slave development and testing.
Micromites and Maximites! - Beginning Maximite
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 04:37am 05 Sep 2018
Copy link to clipboard 
Print this post

Modbus function 05 (Force single coil) question.

Thanks to TassyJim for providing the CRC in MMBasic and CircuitGizmos for recommending Qmodbus my Modbus slave implementation is progressing slowly as time permits.

For those of you who have a wider experience with the use of Modbus than me, I have a question concerning the use of function 05:

I will be using bi-stable relays for the outputs - so two separate pulsed outputs are required - one for ON (close) and one for OFF (trip).

This can be handled by using two points in the memory map, one for "device 1 ON" and one for "device 1 OFF".

An alternative is to have one point in the memory map for "device 1" and use logic within the program to pulse the appropriate ON or OFF output.

Which is the more standard approach?

I am, or rather was, familiar with protection relays for electricity substations that used the first approach.

A third method would be to use a demultiplexer to reduce the number of I/O pins but that's not for me in this case.

Thanks
Biil
Keep safe. Live long and prosper.
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5091
Posted: 06:58am 05 Sep 2018
Copy link to clipboard 
Print this post

If you use the alternate method, you will loose control of the actual state of the relay. There are ways to "remember" the state, but you are never 100% sure. I.e. if there was a short disconnect during a command, you think it is in ON state, while it did not get the pulse, and actually is in OFF state. Out of sync forever after.....

Only way to resync is a slave reset.


PicomiteVGA PETSCII ROBOTS
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 07:25am 05 Sep 2018
Copy link to clipboard 
Print this post

Thanks Volhout, that's a good point.

One of the digital inputs will report the state of the output to the master though, so the master should know the result of the control operation after the next poll (read input status). I am assuming that the master has the responsibility to send the correct command.

Bill
Keep safe. Live long and prosper.
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025