modbus unexpected behaviour

sabbay
Posts: 4
Joined: Thu May 16, 2019 7:59 am

modbus unexpected behaviour

Postby sabbay » Sat May 25, 2019 12:38 pm

Hello,
I`m experimenting with modbus right now. I have 2 ESP32 setup connected as shown https://github.com/espressif/esp-idf/tr ... bus_master here. I`ve flashed example slave for one, example master for second (modified so it only sends requests to slave 1).

Now I get READ events very rarely. So I thought i`d dump the data read from UART like that

Code: Select all

...
        if(p_uart_obj[uart_num]->rx_cur_remain > length) {
            len_tmp = length;
        } else {
            len_tmp = p_uart_obj[uart_num]->rx_cur_remain;
        }
        memcpy(buf + copy_len, p_uart_obj[uart_num]->rx_ptr, len_tmp);
        for(int i = 0; i < len_tmp; i++){
          printf("%02x", buf[i]);
        }
        printf("\n");
        UART_ENTER_CRITICAL(&uart_spinlock[uart_num]);
        p_uart_obj[uart_num]->rx_buffered_len -= len_tmp;
        uart_pattern_queue_update(uart_num, len_tmp);
...
Now i noticed something weird. Requests seems to be the very similar, yet modbus doesn`t recognize them.
Is it a bug, or this can be hardware related?
0001040000000271cb
00010300000002c40b
01030002000265cb
HOLDING READ: time_stamp(us):954205088, mb_addr:3, type:2, st_address:0x3ffb2c80, size:2
01040000000271cb
INPUT READ: time_stamp(us):957362832, mb_addr:1, type:8, st_address:0x3ffb2c6c, size:2
010300000002c40b
HOLDING READ: time_stamp(us):957524114, mb_addr:1, type:2, st_address:0x3ffb2c7c, size:2
01030002000265cb
HOLDING READ: time_stamp(us):957685073, mb_addr:3, type:2, st_address:0x3ffb2c80, size:2
01040000000271cb
INPUT READ: time_stamp(us):960842758, mb_addr:1, type:8, st_address:0x3ffb2c6c, size:2
00010300000002c40b
00010300020002
0001
0001040000000271cb
00010300000002c40b
0001030002000265cb
0001040000000271cb
Thanks in advance!

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

Re: modbus unexpected behaviour

Postby ESP_alisitsyn » Fri May 31, 2019 1:12 pm

Hi sabbay,

Most probably your issue is hardware related (it is typical for RS485 driver connection issue). The Modbus stack can not recognize the packet because it contains first zero byte [00010300000002c40b]. The correct request is: [010300000002c40b] and Modbus can correctly recognize it. Please try to check your connection using example: esp-idf/examples/peripherals/uart/uart_echo_rs485/ first for slave and master board then connect them to each other for Modbus.

--
Alex

Who is online

Users browsing this forum: No registered users and 163 guests