Frame length error - Modbus RTU slave

Hi

I have configured my project to have a Modbus RTU slave on UART1. When I poll the dev kit, using Modscan, I get frame length errors. I have checked baud rate and parity. My board connects to my PC using an rS485 line driver (I don't think this is the problem).

Any suggestions.

Regards Mark

Parents Reply Children
  • Hi Einar

    I configured the UART in the boards dts file:

    &uart1 {
        status = "okay";
        compatible = "nordic,nrf-uarte";
        current-speed = <19200>;
        tx-pin = <40>;
        rx-pin = <38>;
    };

    However, I have now managed to get the Modbus driver to work by hard coding the UART configuration in modbus_serial.c.

    /*TODO remove following hard configuration */
        uart_cfg.baudrate    = 19200;
        uart_cfg.parity        = UART_CFG_PARITY_NONE;
        uart_cfg.stop_bits    = UART_CFG_STOP_BITS_1;
        uart_cfg.data_bits    = UART_CFG_DATA_BITS_8;
        uart_cfg.flow_ctrl    = UART_CFG_FLOW_CTRL_NONE;
        
        if (uart_configure(cfg->dev, &uart_cfg) != 0) {

    The only thing I can think of is the original code is setting the Modbus comms to something I don't want. I will look into this and if I find something I will post you.

    For now, thanks for your help.

    Regards Mark

  • OK - I believe I have found the problem ...

    If no parity is selected the Modbus driver sets stop bits to 2. This is incorrect, it should be left at 1.

    See below (modbus_serial.c):

        switch (param.serial.parity) {
        case UART_CFG_PARITY_ODD:
        case UART_CFG_PARITY_EVEN:
            uart_cfg.parity = param.serial.parity;
            uart_cfg.stop_bits = UART_CFG_STOP_BITS_1;
            break;
        case UART_CFG_PARITY_NONE:
            /* Use of no parity requires 2 stop bits */
            uart_cfg.parity = param.serial.parity;
            uart_cfg.stop_bits = UART_CFG_STOP_BITS_2;
            break;
        default:
            return -EINVAL;
        }

    I would change this to ...

            uart_cfg.parity = param.serial.parity;
            uart_cfg.stop_bits = UART_CFG_STOP_BITS_1;

    Regards Mark

Related