From 3f10640b670ac2e094d13baa455b03dd95c2eeb2 Mon Sep 17 00:00:00 2001 From: aleks Date: Tue, 30 Mar 2021 14:42:44 +0200 Subject: [PATCH] freemodbus: fix issues when modbus master and slave work simultaneously --- components/freemodbus/modbus/mb.c | 2 +- components/freemodbus/port/porttimer_m.c | 2 +- .../serial_slave/modbus_controller/mbc_serial_slave.c | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/components/freemodbus/modbus/mb.c b/components/freemodbus/modbus/mb.c index d847b97e20..bf1032ad79 100644 --- a/components/freemodbus/modbus/mb.c +++ b/components/freemodbus/modbus/mb.c @@ -54,7 +54,7 @@ #endif #ifndef MB_PORT_HAS_CLOSE -#define MB_PORT_HAS_CLOSE 0 +#define MB_PORT_HAS_CLOSE 1 #endif /* ----------------------- Static variables ---------------------------------*/ diff --git a/components/freemodbus/port/porttimer_m.c b/components/freemodbus/port/porttimer_m.c index 85ab1234f5..b0a7f93237 100644 --- a/components/freemodbus/port/porttimer_m.c +++ b/components/freemodbus/port/porttimer_m.c @@ -57,7 +57,7 @@ /* ----------------------- Variables ----------------------------------------*/ static USHORT usT35TimeOut50us; -static const USHORT usTimerIndex = MB_TIMER_INDEX; // Initialize Modbus Timer index used by stack, +static const USHORT usTimerIndex = MB_TIMER_INDEX ^ 1; // Initialize Modbus Timer index used by stack, static const USHORT usTimerGroupIndex = MB_TIMER_GROUP; // Timer group index used by stack static timer_isr_handle_t xTimerIntHandle; // Timer interrupt handle diff --git a/components/freemodbus/serial_slave/modbus_controller/mbc_serial_slave.c b/components/freemodbus/serial_slave/modbus_controller/mbc_serial_slave.c index 85c2266633..ab10cdef5d 100644 --- a/components/freemodbus/serial_slave/modbus_controller/mbc_serial_slave.c +++ b/components/freemodbus/serial_slave/modbus_controller/mbc_serial_slave.c @@ -28,7 +28,7 @@ #include "port_serial_slave.h" // Shared pointer to interface structure -static mb_slave_interface_t* mbs_interface_ptr = NULL; // &default_interface_inst; +static mb_slave_interface_t* mbs_interface_ptr = NULL; // Modbus task function static void modbus_slave_task(void *pvParameters) @@ -36,7 +36,6 @@ static void modbus_slave_task(void *pvParameters) // Modbus interface must be initialized before start MB_SLAVE_ASSERT(mbs_interface_ptr != NULL); mb_slave_options_t* mbs_opts = &mbs_interface_ptr->opts; - MB_SLAVE_ASSERT(mbs_opts != NULL); // Main Modbus stack processing cycle for (;;) {