Setting Stop bits in Modbus Serial

sabin.john
Posts: 7
Joined: Thu Dec 03, 2020 11:53 am

Setting Stop bits in Modbus Serial

Postby sabin.john » Thu Dec 03, 2020 12:06 pm

Hello,

Code: Select all

 * @brief Device communication structure to setup Modbus controller
 */
typedef union {
    // Serial communication structure
    struct {
        mb_mode_type_t mode;                    /*!< Modbus communication mode */
        uint8_t slave_addr;                     /*!< Modbus slave address field (dummy for master) */
        uart_port_t port;                       /*!< Modbus communication port (UART) number */
        uint32_t baudrate;                      /*!< Modbus baudrate */
        uart_parity_t parity;                   /*!< Modbus UART parity settings */
        uint16_t dummy_port;                    /*!< Dummy field, unused */
    };
    // TCP/UDP communication structure
    struct {
        mb_mode_type_t ip_mode;                /*!< Modbus communication mode */
        uint16_t ip_port;                      /*!< Modbus port */
        mb_tcp_addr_type_t ip_addr_type;       /*!< Modbus address type */
        void* ip_addr;                         /*!< Modbus address table for connection */
        void* ip_netif_ptr;                    /*!< Modbus network interface */
    };
} mb_communication_info_t;
The init driver initializes Modbus using the above parameters. I am using Modbus RTU and I wanted to know if the number of stop bits can be configured or not. Is the driver written in such a way that when either odd/even parity is selected number of stop bits are automatically initialized to 1 and when the parity is none, number of stop bits is set to 2. Is there anyway to configure it on an user level like the other elements of mb_communication_info_t .

ESP_alisitsyn
Posts: 211
Joined: Fri Feb 01, 2019 4:02 pm
Contact:

Re: Setting Stop bits in Modbus Serial

Postby ESP_alisitsyn » Tue Jan 12, 2021 4:46 pm

Hello @sabin.john,

The additional option in `mb_communication_info_t` can be implemented. The reason why it was not implemented is compatibility with original freemodbus code which does not provide a way to explicitly select number of stop bits (See the
BOOL xMBPortSerialInit(Char ucPORT, ULONG ulBaudRate, Char ucDataBits, eMBParity parity)
function). It usually not required to use second stop bit because most of the modern UART devices are able to receive data correctly with one stop bit even when configured for two bits. If you have a strong opinion about this option I will change the signature of the init functions and propagate corresponded modbus controller option into port initialization function. You are not the first person who ask to implement this that confirms this feature request.

I will add this feature implementation into my queue.
Thanks.

Who is online

Users browsing this forum: No registered users and 77 guests