diff --git a/components/net/freemodbus/Kconfig b/components/net/freemodbus/Kconfig index 9321c61a0eae5322a82253f4a36c70ea7b62e49a..1dbeca31d9b3f34e888c21eced19d19efced88cd 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 0ad33d7a7c5741dcfb1f4a244d96538e97a7c462..7c546a1691e50e780e4f6c1505dd83475829533e 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 ce3e69f38263ed522587cb0a5a34ec15dda780c6..71f490f5fac69a4beaddc8409e3cce87e4f0773a 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