Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Modbusino] - simple modbus rtu library #2043

Merged
merged 36 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
94735bb
Add modbusino library + patch + sample
kmihaylov Feb 1, 2020
2f762e7
Merge branch 'develop' of https://github.com/SmingHub/Sming into feat…
kmihaylov Feb 1, 2020
b1b5323
Fix modbusino's component.mk component variables assignation, += inst…
kmihaylov Feb 1, 2020
2be888f
Add delays when sending a message.
kmihaylov Feb 1, 2020
00e5b36
Changes to generic sample. Proper initialization (not yet done) of RE…
kmihaylov Feb 1, 2020
a216f2e
Make the MB slave address a config variable
kmihaylov Feb 5, 2020
d83ba81
New patch file introducing configurable pre- and post-transmission de…
kmihaylov Feb 5, 2020
d12aabe
Modify example and component.mk to support MB_SLAVE_ADDR
kmihaylov Feb 5, 2020
64a28ce
Add README file for the component
kmihaylov Feb 5, 2020
e00c137
URL to the original repository is added
kmihaylov Feb 5, 2020
44c5a9c
Fix a typo
kmihaylov Feb 5, 2020
a6c4363
Update sample's README
kmihaylov Feb 5, 2020
f97a89f
Requested changes
kmihaylov Feb 6, 2020
abe7d5d
Requested changes
kmihaylov Feb 6, 2020
947caa7
Minor documentation tweaks. Keep consistent style.
mikee47 Feb 6, 2020
ccf0e80
Change modbusino origin url
kmihaylov Feb 6, 2020
932f622
Remote modbusino.patch. Sming dedicated fork is used
kmihaylov Feb 6, 2020
c157b74
modbusino updates
kmihaylov Feb 7, 2020
d141a7c
use modbusino.setup() for serial initialization
kmihaylov Feb 7, 2020
b89f799
modbusino updates
kmihaylov Feb 7, 2020
4a47fdf
Towards event driven modbusino
kmihaylov Feb 7, 2020
14b3cdf
Update Modbusino fork
kmihaylov Feb 8, 2020
d673721
Remove timers. Use RX calback for modbus
kmihaylov Feb 9, 2020
241f145
Update modbusino fork. Use of callbacks
kmihaylov Feb 9, 2020
e859bcd
Update modbusino fork. Do not use rxCallback when master only reads r…
kmihaylov Feb 9, 2020
fb9fa8b
Update modbusino library
kmihaylov Apr 14, 2020
a573d54
Merge branch 'develop' of https://github.com/SmingHub/Sming into feat…
kmihaylov Apr 14, 2020
aa5fbcb
Update modbusino library
kmihaylov Apr 14, 2020
3720d43
Fix coding style, add .cs
kmihaylov Apr 15, 2020
d9f3e54
make cs
kmihaylov Apr 15, 2020
30900f6
Update README.rst, loop not used, remove of PRE and POST delay variables
kmihaylov Apr 23, 2020
e43f2ff
Update samle's README
kmihaylov Apr 23, 2020
fc70591
Update the global modbusino README and component.mk
kmihaylov Apr 23, 2020
1644e10
Update README introducing some information about the observed RE line…
kmihaylov May 7, 2020
6676735
Update submodule hash
kmihaylov May 7, 2020
63f6512
Fix conflict on .gitmodules, update branch
kmihaylov May 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,7 @@
path = Sming/Libraries/Adafruit_VL53L0X
url = https://github.com/adafruit/Adafruit_VL53L0X.git
ignore = dirty
[submodule "Libraries.modbusino"]
path = Sming/Libraries/modbusino/modbusino
url = https://github.com/kmihaylov/modbusino.git
ignore = dirty
37 changes: 37 additions & 0 deletions Sming/Libraries/modbusino/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
modbusino RTU Library (modbus slave)
====================================

modbusino is lightweight RTU `Modbus <https://en.wikipedia.org/wiki/Modbus>`__
slave library that supports 'read holding registers' and 'write multiple registers' functions.


Configuration variables
-----------------------


.. envvar:: RS485_RE_PIN

Default: 15

GPIO pin number for RE (Receive-Enable) output.


.. envvar:: RS485_TX_LEVEL

Default: HIGH.

Active level for RE pin during transmission.


.. envvar:: MB_PRE_TX_DELAY

Default: 100 (microseconds).

Time to wait after RE pin level change, before writing serial data. Used to ensure proper line detection by the master device.


.. envvar:: MB_POST_TX_DELAY

Default: 1000 (microseconds).

Delay after data transmission, before RE pin level change.
kmihaylov marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 19 additions & 0 deletions Sming/Libraries/modbusino/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
COMPONENT_SUBMODULES := modbusino
COMPONENT_SRCDIRS := modbusino
COMPONENT_INCDIRS := modbusino

COMPONENT_VARS += RS485_RE_PIN
RS485_RE_PIN ?= 15
COMPONENT_CXXFLAGS += -DRS485_RE_PIN=$(RS485_RE_PIN)

COMPONENT_VARS += RS485_TX_LEVEL
RS485_TX_LEVEL ?= HIGH
COMPONENT_CXXFLAGS += -DRS485_TX_LEVEL=$(RS485_TX_LEVEL)

COMPONENT_VARS += MB_PRE_TX_DELAY
MB_PRE_TX_DELAY ?= 100
COMPONENT_CXXFLAGS += -DMB_PRE_TX_DELAY=$(MB_PRE_TX_DELAY)

COMPONENT_VARS += MB_POST_TX_DELAY
MB_POST_TX_DELAY ?= 1000
COMPONENT_CXXFLAGS += -DMB_POST_TX_DELAY=$(MB_POST_TX_DELAY)
kmihaylov marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions Sming/Libraries/modbusino/modbusino
Submodule modbusino added at f97f85
9 changes: 9 additions & 0 deletions Sming/Libraries/modbusino/samples/generic/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#####################################################################
#### Please don't change this file. Use component.mk instead ####
#####################################################################

ifndef SMING_HOME
$(error SMING_HOME is not set: please configure it as an environment variable)
endif

include $(SMING_HOME)/project.mk
16 changes: 16 additions & 0 deletions Sming/Libraries/modbusino/samples/generic/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Modbusino RTU generic sample
============================

kmihaylov marked this conversation as resolved.
Show resolved Hide resolved
.. highlight:: bash

The sample code provides three element uint16_t array used for the modbus slave registers. These values are printed each second through UART1.
mbSlaveLoopTimer checks for new data each 10 milliseconds (Only checks for new data. Serial communication is handled by hardware.)
kmihaylov marked this conversation as resolved.
Show resolved Hide resolved

Several environment variables (envvar:`RS485_RE_PIN` :envvar:`RS485_TX_LEVEL` :envvar:`MB_PRE_TX_DELAY` :envvar:`MB_POST_TX_DELAY`) can be used for configuration.
kmihaylov marked this conversation as resolved.
Show resolved Hide resolved
The slave address is defined with envvar:`MB_SLAVE_ADDR`. For example::

make MB_SLAVE_ADDR=2

These variables can be listed with::

make list-config
24 changes: 24 additions & 0 deletions Sming/Libraries/modbusino/samples/generic/app/application.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <SmingCore.h>
slaff marked this conversation as resolved.
Show resolved Hide resolved
#include <Debug.h>
#include <Modbusino.h>

#define ARRLEN 3
uint16_t mbDataArray[ARRLEN] = {0,0,0};
ModbusinoSlave MbSlave(MB_SLAVE_ADDR, mbDataArray, ARRLEN);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename MbSlave to mbSlave to match the coding style.


HardwareSerial debugComPort(UART1);

void mbPrint() {
debugf("Register values, #0: %d, #1: %d, #2: %d", mbDataArray[0], mbDataArray[1], mbDataArray[2]);
}

void init()
{
debugComPort.begin(SERIAL_BAUD_RATE, SERIAL_8N1,
SERIAL_TX_ONLY);
debugComPort.systemDebugOutput(true);
Debug.setDebug(debugComPort);
Debug.start();
MbSlave.setup(SERIAL_BAUD_RATE);
MbSlave.setRxCallback(mbPrint);
}
6 changes: 6 additions & 0 deletions Sming/Libraries/modbusino/samples/generic/component.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ARDUINO_LIBRARIES := modbusino
DISABLE_SPIFFS = 1

CONFIG_VARS += MB_SLAVE_ADDR
MB_SLAVE_ADDR ?= 1
APP_CFLAGS += -DMB_SLAVE_ADDR=$(MB_SLAVE_ADDR)