Zephyr Modbus RTU "Frame Error"

Hello all,

I'm using the adafruit itsy bitsy for this modbus project and having issue to communicate with my usb-rs485 using modbus poll software. The protocol is Modbus RTU Slave and the error is <wrn> modbus_serial: Frame length error.

Any thoughts are appreciated!

here is my overlay file:

&uart0 {
    status = "okay";
    parity = "even";
    modbus0 {
        compatible = "zephyr,modbus-serial";
        status = "okay";
        //de-gpios = <&arduino_header 15 GPIO_ACTIVE_LOW>;  /* D9 */
    };
};
Parents
  • Hi,

    For us to help you with this in the best possible way, please list the following information:

    • SDK Version
    • Which sample do you use, if any?
    • Do you use custom code?
    • What is the full log from the device?

     Regards,
    Sigurd Hellesvik

  • SDK Version: Zephyr version: 3.7.0-rc2
    Full log of device:
    [00:00:00.249,450] <inf> modbus_serial: RTU timeout 2005 us
    [00:00:00.250,579] <wrn> modbus: Client wait-for-RX timeout
    [00:00:00.250,579] <err> mbc_sample: FC16 failed with -116
    [00:00:00.281,921] <wrn> modbus_serial: Frame length error
    This is my code:

     */
    #include <zephyr/kernel.h>
    #include <zephyr/sys/util.h>
    #include <zephyr/drivers/gpio.h>
    #include <zephyr/modbus/modbus.h>
    #include <zephyr/logging/log.h>

    /* 1000 msec = 1 sec */
    #define SLEEP_TIME_MS   1000

    LOG_MODULE_REGISTER(mbc_sample, LOG_LEVEL_INF);
    /* The devicetree node identifier for the "led0" alias.*/

    static int client_iface;

    const static struct modbus_iface_param client_param = {
        .mode = MODBUS_MODE_RTU,
        .rx_timeout = 1000,
        .serial = {
            .baud = 19200,
            .parity = UART_CFG_PARITY_EVEN,
            .stop_bits_client = UART_CFG_STOP_BITS_1,
        },  
    };

    #define MODBUS_NODE DT_COMPAT_GET_ANY_STATUS_OKAY(zephyr_modbus_serial)

    static int init_modbus_client(void)
    {
        const char iface_name[] = {DEVICE_DT_NAME(MODBUS_NODE)};

        client_iface = modbus_iface_get_by_name(iface_name);

        return modbus_init_client(client_iface, client_param);
    }

    int main(void)

    {
        uint16_t holding_reg[8] = {'H', 'e', 'l', 'l', 'o'};
        const uint8_t coil_qty = 3;
        uint8_t coil[1] = {0};
        const int32_t sleep = 3000;
        static uint8_t node = 1;
        int err;
        uint8_t received[10];

        if (init_modbus_client()) {
            LOG_ERR("Modbus RTU client initialization failed");
            return 0;
        }

        err = modbus_write_holding_regs(client_iface, node, 0, holding_reg,
                        ARRAY_SIZE(holding_reg));
        if (err != 0) {
            LOG_ERR("FC16 failed with %d", err);
        }



    }
  • I see that you get the error message "FC16 failed with -116". From errno.h this looks like EHOSTDOWN.
    Try to check when modbus_write_holding_regs returns this error?

  • I got it received the data now. However I'm not about to transmit. I connect the B- to Uart Tx but seem like it doesn't work that way. Is there any way I can transmit rs-485 without transceiver?

Reply Children
Related