From 125235c61c31f951b3e8d60d6d6a9fc091e10aa9 Mon Sep 17 00:00:00 2001 From: liquanqing Date: Mon, 25 Jun 2018 14:15:32 +0800 Subject: [PATCH] add freemodbus slave contorl pin config in Kconfig --- components/net/freemodbus/Kconfig | 10 ++++++++++ components/net/freemodbus/port/portserial.c | 13 +++++++++---- components/net/freemodbus/port/user_mb_app.h | 3 --- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/components/net/freemodbus/Kconfig b/components/net/freemodbus/Kconfig index 9321c61a0e..1dbeca31d9 100644 --- a/components/net/freemodbus/Kconfig +++ b/components/net/freemodbus/Kconfig @@ -12,6 +12,16 @@ config RT_USING_MODBUS config RT_MODBUS_SLAVE_RTU bool "RTU slave mode" default n + if RT_MODBUS_SLAVE_RTU + config RT_MODBUS_SLAVE_USE_CONTROL_PIN + bool "Use Contorl Pin" + default n + if RT_MODBUS_SLAVE_USE_CONTROL_PIN + config MODBUS_SLAVE_RT_CONTROL_PIN_INDEX + int "pin index for RS485 TX/RX select" + default 10 + endif + endif endif endmenu diff --git a/components/net/freemodbus/port/portserial.c b/components/net/freemodbus/port/portserial.c index 0ad33d7a7c..7c546a1691 100644 --- a/components/net/freemodbus/port/portserial.c +++ b/components/net/freemodbus/port/portserial.c @@ -56,8 +56,9 @@ BOOL xMBPortSerialInit(UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, * set 485 mode receive and transmit control IO * @note MODBUS_SLAVE_RT_CONTROL_PIN_INDEX need be defined by user */ - //rt_pin_mode(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_MODE_OUTPUT); - +#if defined(RT_MODBUS_SLAVE_USE_CONTROL_PIN) + rt_pin_mode(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_MODE_OUTPUT); +#endif /* set serial name */ if (ucPORT == 1) { #if defined(RT_USING_UART1) || defined(RT_USING_REMAP_UART1) @@ -127,12 +128,16 @@ void vMBPortSerialEnable(BOOL xRxEnable, BOOL xTxEnable) /* enable RX interrupt */ serial->ops->control(serial, RT_DEVICE_CTRL_SET_INT, (void *)RT_DEVICE_FLAG_INT_RX); /* switch 485 to receive mode */ - //rt_pin_write(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_LOW); +#if defined(RT_MODBUS_SLAVE_USE_CONTROL_PIN) + rt_pin_write(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_LOW); +#endif } else { /* switch 485 to transmit mode */ - //rt_pin_write(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_HIGH); +#if defined(RT_MODBUS_SLAVE_USE_CONTROL_PIN) + rt_pin_write(MODBUS_SLAVE_RT_CONTROL_PIN_INDEX, PIN_HIGH); +#endif /* disable RX interrupt */ serial->ops->control(serial, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX); } diff --git a/components/net/freemodbus/port/user_mb_app.h b/components/net/freemodbus/port/user_mb_app.h index ce3e69f382..71f490f5fa 100644 --- a/components/net/freemodbus/port/user_mb_app.h +++ b/components/net/freemodbus/port/user_mb_app.h @@ -25,9 +25,6 @@ /* salve mode: discrete's all address */ #define S_DI_RESERVE 0 /* slave mode: holding register"s startup address */ -#define S_SYSTEM_START_ADDR 0x003A -#define S_SYSTEM_SLAVE_ID_ADDR 0x0040 -#define S_SYSTEM_KEEP_TEMP 0x0009 /* -----------------------Master Defines -------------------------------------*/ #define M_DISCRETE_INPUT_START 1