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
  • I have configured the project to implement a simple UART and not the Modbus module. I have verified that the frame is coming in ....

    but it seems to come in a character at a time i.e. each time I receive a character I get an interrupt and the character is handled individually. It is as though the driver doesn't tolerate contiguous characters. So I don't get a complete message in the FIFO.

    Is there something I am missing in the UART configuration ?

    Regards Mark

  • Hi Mark,

    Mark Payne said:
    Is there something I am missing in the UART configuration ?

    That could be. How have you configured / implemented UART communication on the nRF side? It is certainly possible to configure single byte transactions, but the UARTE peripheral does have DMA and allows long transactions without CPU involvements.

  • 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