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

  • 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