Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 07:09 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 1 of 2    
Author Message
memberx
Newbie

Joined: 20/04/2012
Location: Australia
Posts: 24
Posted: 01:27am 08 Feb 2013
Copy link to clipboard 
Print this post

I am looking at a possibility of using PIC-32 MMBasic based controller in RS485 network that uses Modbus Serial RTU protocol, both as Master and Slaves.

For those not familiar. Modbus is a protocol generally based on RS485 network with one master and multiple polled slaves. It is used widely in Industrial applications controlling PLCs (Programmable logic controllers). But, there are also a lot of peripherals such as Digital I/O and Analog I/O modules, also various sensors like Temperature, Humidity, CO2 etc that use Modbus Protocol.

It would be possible to write the protocol routines in MMBasic or it would be even much nicer if Geoff could make Modbus part of MMBasic in the future.

Has anyone written/developed any code in MMBasic on Maximite or similar for Modbus?
 
CircuitGizmos

Guru

Joined: 08/09/2011
Location: United States
Posts: 1427
Posted: 05:09am 08 Feb 2013
Copy link to clipboard 
Print this post

  memberx said   I am looking at a possibility of using PIC-32 MMBasic based controller in RS485 network that uses Modbus Serial RTU protocol, both as Master and Slaves.

For those not familiar. Modbus is a protocol generally based on RS485 network with one master and multiple polled slaves. It is used widely in Industrial applications controlling PLCs (Programmable logic controllers). But, there are also a lot of peripherals such as Digital I/O and Analog I/O modules, also various sensors like Temperature, Humidity, CO2 etc that use Modbus Protocol.

It would be possible to write the protocol routines in MMBasic or it would be even much nicer if Geoff could make Modbus part of MMBasic in the future.

Has anyone written/developed any code in MMBasic on Maximite or similar for Modbus?


This is on my to-do list.
Micromites and Maximites! - Beginning Maximite
 
expo
Newbie

Joined: 10/01/2016
Location: Australia
Posts: 25
Posted: 06:40pm 04 Apr 2016
Copy link to clipboard 
Print this post

Hello memberx & CircuitGizmos,

Any progression on this topic?

expo
 
drkl

Senior Member

Joined: 18/10/2015
Location: Hungary
Posts: 102
Posted: 07:12pm 04 Apr 2016
Copy link to clipboard 
Print this post

Hello,
The CRC calculation is very difficult in the RTU protocol.
If it is solved, the other parts is relatively simple to program.
It would be better to use the ASCII protocol. It uses a simple control sum.

drkl

 
drkl

Senior Member

Joined: 18/10/2015
Location: Hungary
Posts: 102
Posted: 07:16pm 04 Apr 2016
Copy link to clipboard 
Print this post

Sorry,
Now I have seen the processor datasheet, and there is a built-in CRC engine!!!
So CRC calculation is would be simple
drkl
 
LouisG
Senior Member

Joined: 19/03/2016
Location: Australia
Posts: 129
Posted: 12:16am 11 Apr 2017
Copy link to clipboard 
Print this post


I would like to refresh Expo's query (above) about whether there is any progression on the topic.

My interest is in Modbus/ASCII.

-
 
expo
Newbie

Joined: 10/01/2016
Location: Australia
Posts: 25
Posted: 07:35pm 11 Apr 2017
Copy link to clipboard 
Print this post

+1 ...(again)
 
goc30

Guru

Joined: 12/04/2017
Location: France
Posts: 435
Posted: 10:28pm 11 Apr 2017
Copy link to clipboard 
Print this post

hi all
i am newbie in this forum

i have wrote modbus progs (master and slave) in vb6
i can translate this for micromite
It work in interrupt mode (for reception). The best is to use interrupt mode for transmit (use int write buffer empty and transmit buffer) but
 
LouisG
Senior Member

Joined: 19/03/2016
Location: Australia
Posts: 129
Posted: 05:21am 13 Apr 2017
Copy link to clipboard 
Print this post


but...? But what? Your post was cut short (Interrupt mode?).

But - welcome to the Forum, goc30!

I and others would be very interested in Micromite having Modbus capability.


 
goc30

Guru

Joined: 12/04/2017
Location: France
Posts: 435
Posted: 06:18am 13 Apr 2017
Copy link to clipboard 
Print this post

Iam sorry for the "but"

i said that the signal "transmit buffer empty" is not aviable directly in mmbasic. May be this signal is used by geoffrey when sending buffer (and in this case, cpu is free to do other think between each byte send) or mmbasic wait for this signal.

but this is important if you want to make a real-time process in the slave machine.
If you work in sequential mode (like: acq i/o and after listen if master "speak", and so..) this is not important.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 06:47am 13 Apr 2017
Copy link to clipboard 
Print this post

It sounds like anything (simple by all means) that works would be welcomed.

MMBasic overlaps serial I/O somewhat so maybe start with the simplest conversion of your current code that works, then ask people to try it / suggest improvements / etc.

John
 
LouisG
Senior Member

Joined: 19/03/2016
Location: Australia
Posts: 129
Posted: 08:13am 13 Apr 2017
Copy link to clipboard 
Print this post

Perhaps for a start, use a Micromite as a simple I/O board that responds to serial Modbus requests.

 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 08:43am 13 Apr 2017
Copy link to clipboard 
Print this post

I forgot to mention: by all means post VB code if you get stuck figuring out MMBasic equivalents or want ideas. Maybe someone will have them.

John
 
goc30

Guru

Joined: 12/04/2017
Location: France
Posts: 435
Posted: 12:53pm 13 Apr 2017
Copy link to clipboard 
Print this post

louisG
Perhaps for a start, use a Micromite as a simple I/O board that responds to serial Modbus requests.

In all cases, i begin to prog slave mode with Pc as master
after, i prog master mode

but first time i need to define I/O (smalls) tables and I/O (simples) functions
I use mx170-44pins controller as slave
 
goc30

Guru

Joined: 12/04/2017
Location: France
Posts: 435
Posted: 06:08am 19 Apr 2017
Copy link to clipboard 
Print this post

I have finish the proto board and write skeleton of programm

i think finish slave mode at end of week
 
Turbo46

Guru

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

Hi goc30,

I would like to make a Modbus master using either the Maximite or Micromite backpack and a couple of slaves (RTUs) with the micromite. Have you made any progress with this? I have some questions if you wouldn't mind:

What Modbus PC master do you use? I have found some free ones but I am not confident about using them.

How do you handle a bi-stable output (open/close) which requires two pulsed outputs for one controlled device? Is that one special control (coil) output OR two separate controls, one for open and one for close?

I have the CRC working OK thanks to TassyJim. BTW a Cfuntion for this would be very handy.

Thanks
Bill
Keep safe. Live long and prosper.
 
goc30

Guru

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

Hi Turbo46,

I developed my own MODBUS software, it was my job a while ago. it was developed in vb6.
I started writing in mmbasic, but I have a problem: the absence of an interrupt on transmission of the COM port.
In the industrial field and given that MMbasic is an interpreter, it is necessary to manage the COM port for transmission and reception with interruptions (in 1 app i use GPS and MODBUS, this is impossible in polling mode).
In addition to rpi there is no interruption (which is less serious given the speeds) and especially the management of COM ports is not serious (in industrial world), too much change incompatible (see rpi3b+ and strech vs rpi2 and jessie)
 
matherp
Guru

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

  Quote   the absence of an interrupt on transmission of the COM port.


Do you mean you want a "transmit buffer empty" interrupt to a Basic subroutine? If so this is pretty easy to engineer. If you confirm I'll put it into the STM32H7 port and you can have a play. Then it would be up to you persuading Geoff of its merits if you want it in the MM2, MM+
 
goc30

Guru

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

Hi peter

Yes i confirm
task who want to send message, call function "F" who, when receive buffer, send first char and "sleep"
interrupt call function "F". When transmit buffer is empty, function "F" send the next char, and so one.. In last char, function "F" put flag "finish"

As i said, i nedd this one for an appli who use port COM for GPS and other for Modbus exchange with 3 slaves

If you can do this, i while bee the most happy boy in the world
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10315
Posted: 01:48pm 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?
 
     Page 1 of 2    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025