![]() |
Forum Index : Microcontroller and PC projects : Modbus Protocol in MMBasic
Page 1 of 2 ![]() ![]() |
|||||
Author | Message | ||||
memberx Newbie ![]() Joined: 20/04/2012 Location: AustraliaPosts: 24 |
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 StatesPosts: 1427 |
This is on my to-do list. Micromites and Maximites! - Beginning Maximite |
||||
expo Newbie ![]() Joined: 10/01/2016 Location: AustraliaPosts: 25 |
Hello memberx & CircuitGizmos, Any progression on this topic? expo |
||||
drkl![]() Senior Member ![]() Joined: 18/10/2015 Location: HungaryPosts: 102 |
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: HungaryPosts: 102 |
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: AustraliaPosts: 129 |
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: AustraliaPosts: 25 |
+1 ...(again) |
||||
goc30![]() Guru ![]() Joined: 12/04/2017 Location: FrancePosts: 435 |
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: AustraliaPosts: 129 |
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: FrancePosts: 435 |
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 KingdomPosts: 4044 |
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: AustraliaPosts: 129 |
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 KingdomPosts: 4044 |
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: FrancePosts: 435 |
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: FrancePosts: 435 |
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: AustraliaPosts: 1642 |
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: FrancePosts: 435 |
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 KingdomPosts: 10315 |
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: FrancePosts: 435 |
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 KingdomPosts: 10315 |
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 ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |