Modbus slave

Chriserke
Posts: 9
Joined: Mon Mar 09, 2020 1:56 pm

Modbus slave

Postby Chriserke » Mon Mar 09, 2020 2:36 pm

Hello,

i've been trying to run the esp-idf modbus slave example in combination with a modbus master/poll tool.

Before this i've verified the working of the rs485 transceiver module with the rs485 echo example and a rs485 cable to the pc.

However running the slave modbus example gives a timeout reading on every tool for some reason.
I've tried more or less every combination for the serial port so i'm not quite sure why it isn't working at this point.
I've also tried a lower baudrates to see if that might've been an issue.

Is there something that needs to be changed in the slave code or in the modbus master tool perhaps?
The esp-idf version is 4.0 in comibation with visual studio/visualGDB
Attachments
settings.png
settings.png (9.83 KiB) Viewed 2491 times

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

Re: Modbus slave

Postby ESP_alisitsyn » Mon Mar 09, 2020 3:19 pm

Hi @Chriserke,

The Modbus slave example works just fine with Modbus Poll tool. The error with timeout (ESP_ERR_TIMEOUT = 0x107) is related to communication parameters or connection issue. Please check if you use the same parameters in the example and on host side. If echo_RS485 example works just fine then it is just communication parameter issue. The modbus_slave example uses default baudrate = 115200, 8N1, NO PARITY, but it can be easily changed in the example configuration. Also do not forget to select correct communication mode in the KConfig menu item "Modbus communication mode" accordingly (default is MB_COMM_MODE_RTU). Please also check readme.md file in the example folder which can help to configure example correctly.

--
Alex
Last edited by ESP_alisitsyn on Tue Mar 10, 2020 8:09 am, edited 1 time in total.

Chriserke
Posts: 9
Joined: Mon Mar 09, 2020 1:56 pm

Re: Modbus slave

Postby Chriserke » Mon Mar 09, 2020 3:25 pm

Hello,

The error stems from the modbus poll tool.

I have changed the baudrate in the example to 9600 and the uart pins to RX 16 and TX17.
With the mode being default so i believe RTU on the esp side.

On the image below you can see the settings/error.
Would you have an idea as to what is the problem here?






EDIT: this is in the konfig file. I seem to have changed the RX and TX pins.

menu "Modbus Slave Example Configuration"

config MB_UART_RXD
int "UART RXD pin number"
range 0 34
default 16
help
GPIO number for UART RX pin. See UART documentation for more information
about available pin numbers for UART.

config MB_UART_TXD
int "UART TXD pin number"
range 0 34
default 17
help
GPIO number for UART TX pin. See UART documentation for more information
about available pin numbers for UART.

config MB_UART_RTS
int "UART RTS pin number"
range 0 34
default 18
help
GPIO number for UART RTS pin. This pin is connected to
~RE/DE pin of RS485 transceiver to switch direction.

endmenu
Attachments
Example.png
Example.png (21.88 KiB) Viewed 2460 times

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

Re: Modbus slave

Postby ESP_alisitsyn » Tue Mar 10, 2020 8:22 am

Hi @Chriserke,

Please check your connection again using echo_rs485 example. If you use the ESP32-Wrover module on your board the pins IO16,IO17 will not work because they are used for PSRAM connection.
```// Note: UART2 default pins IO16, IO17 do not work on ESP32-WROVER module ```
Please try to set pins IO22, IO23 in the kconfig menu (idf.py menuconfig >>> Modbus Slave Example Configuration) instead.

I guess this should help.

--
Alex

Chriserke
Posts: 9
Joined: Mon Mar 09, 2020 1:56 pm

Re: Modbus slave

Postby Chriserke » Tue Mar 10, 2020 8:45 am

Hello,

The board used is a custom PCB with an esp32 WROOM 32D.
Would this still be the case?

Chriserke
Posts: 9
Joined: Mon Mar 09, 2020 1:56 pm

Re: Modbus slave

Postby Chriserke » Wed Mar 11, 2020 9:25 am

The esp seems to be rebooting when using the modbus. with the following error:

assertion "( eRcvState == STATE_RX_RCV ) || ( eRcvState == STATE_RX_WAIT_EOF )" failed: file "C:/SysGCC/esp32/esp-idf/v4.0/components/freemodbus/modbus/ascii/mbascii.c", line 424, function: xMBASCIITimerT1SExpired
abort() was called at PC 0x400db25f on core 0

ELF file SHA256: 072850ce245344f4140f4c6a65fbdf6f684656638e361b8a9205fd5f54dd5abb

Backtrace: 0x400856c5:0x3ffb9110 0x40085a39:0x3ffb9130 0x400db25f:0x3ffb9150 0x400d5dce:0x3ffb9180 0x400d62b1:0x3ffb91a0 0x400d62d9:0x3ffb91c0 0x40087c35:0x3ffb91f0

Rebooting...
ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:6904
load:0x40078000,len:14076
load:0x40080400,len:4304
entry 0x400806e8
I (71) boot: Chip Revision: 1
I (71) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (39) boot: ESP-IDF -128-NOTFOUND 2nd stage bootloader
I (39) boot: compile time 15:49:52
I (40) boot: Enabling RNG early entropy source...
I (45) boot: SPI Speed : 40MHz
I (49) boot: SPI Mode : DIO
I (53) boot: SPI Flash Size : 2MB
I (57) boot: Partition Table:
I (61) boot: ## Label Usage Type ST Offset Length
I (68) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (75) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (83) boot: 2 factory factory app 00 00 00010000 00100000
I (90) boot: End of partition table
I (95) boot_comm: chip revision: 1, min. application chip revision: 0
I (102) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x08e04 ( 36356) map
I (124) esp_image: segment 1: paddr=0x00018e2c vaddr=0x3ffb0000 size=0x02108 ( 8456) load
I (127) esp_image: segment 2: paddr=0x0001af3c vaddr=0x40080000 size=0x00400 ( 1024) load
I (131) esp_image: segment 3: paddr=0x0001b344 vaddr=0x40080400 size=0x04ccc ( 19660) load
I (148) esp_image: segment 4: paddr=0x00020018 vaddr=0x400d0018 size=0x18980 (100736) map
I (185) esp_image: segment 5: paddr=0x000389a0 vaddr=0x400850cc size=0x05b1c ( 23324) load
I (201) boot: Loaded app from partition at offset 0x10000
I (202) boot: Disabling RNG early entropy source...
I (202) cpu_start: Pro cpu up.
I (206) cpu_start: Application information:
I (210) cpu_start: Project name: modbus_slave
I (216) cpu_start: App version: 1
I (220) cpu_start: Compile time: Mar 10 2020 15:49:30
I (226) cpu_start: ELF file SHA256: 072850ce245344f4...
I (232) cpu_start: ESP-IDF: -128-NOTFOUND
I (238) cpu_start: Starting app cpu, entry point is 0x40081078
I (225) cpu_start: App cpu up.
I (248) heap_init: Initializing. RAM available for dynamic allocation:
I (255) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (261) heap_init: At 3FFB33E8 len 0002CC18 (179 KiB): DRAM
I (268) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (274) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (280) heap_init: At 4008ABE8 len 00015418 (85 KiB): IRAM
I (287) cpu_start: Pro cpu start user code
I (305) spi_flash: detected chip: generic
I (305) spi_flash: flash io: dio
W (305) spi_flash: Detected size(16384k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (316) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (328) uart: queue free spaces: 20
assertion "( eRcvState == STATE_RX_RCV ) || ( eRcvState == STATE_RX_WAIT_EOF )" failed: file "C:/SysGCC/esp32/esp-idf/v4.0/components/freemodbus/modbus/ascii/mbascii.c", line 424, function: xMBASCIITimerT1SExpired
abort() was called at PC 0x400db25f on core 0

ELF file SHA256: 072850ce245344f4140f4c6a65fbdf6f684656638e361b8a9205fd5f54dd5abb

Backtrace: 0x400856c5:0x3ffb9110 0x40085a39:0x3ffb9130 0x400db25f:0x3ffb9150 0x400d5dce:0x3ffb9180 0x400d62b1:0x3ffb91a0 0x400d62d9:0x3ffb91c0 0x40087c35:0x3ffb91f0

Rebooting...
ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:6904
load:0x40078000,len:14076
load:0x40080400,len:4304
entry 0x400806e8
I (71) boot: Chip Revision: 1
I (71) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (39) boot: ESP-IDF -128-NOTFOUND 2nd stage bootloader
I (39) boot: compile time 15:49:52
I (40) boot: Enabling RNG early entropy source...
I (45) boot: SPI Speed : 40MHz
I (49) boot: SPI Mode : DIO
I (53) boot: SPI Flash Size : 2MB
I (57) boot: Partition Table:
I (61) boot: ## Label Usage Type ST Offset Length
I (68) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (75) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (83) boot: 2 factory factory app 00 00 00010000 00100000
I (90) boot: End of partition table
I (95) boot_comm: chip revision: 1, min. application chip revision: 0
I (102) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x08e04 ( 36356) map
I (124) esp_image: segment 1: paddr=0x00018e2c vaddr=0x3ffb0000 size=0x02108 ( 8456) load
I (127) esp_image: segment 2: paddr=0x0001af3c vaddr=0x40080000 size=0x00400 ( 1024) load
I (131) esp_image: segment 3: paddr=0x0001b344 vaddr=0x40080400 size=0x04ccc ( 19660) load
I (148) esp_image: segment 4: paddr=0x00020018 vaddr=0x400d0018 size=0x18980 (100736) map
I (185) esp_image: segment 5: paddr=0x000389a0 vaddr=0x400850cc size=0x05b1c ( 23324) load
I (201) boot: Loaded app from partition at offset 0x10000
I (202) boot: Disabling RNG early entropy source...
I (202) cpu_start: Pro cpu up.
I (206) cpu_start: Application information:
I (210) cpu_start: Project name: modbus_slave
I (216) cpu_start: App version: 1
I (220) cpu_start: Compile time: Mar 10 2020 15:49:30
I (226) cpu_start: ELF file SHA256: 072850ce245344f4...
I (232) cpu_start: ESP-IDF: -128-NOTFOUND
I (238) cpu_start: Starting app cpu, entry point is 0x40081078
I (225) cpu_start: App cpu up.
I (248) heap_init: Initializing. RAM available for dynamic allocation:
I (255) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (261) heap_init: At 3FFB33E8 len 0002CC18 (179 KiB): DRAM
I (268) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (274) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (280) heap_init: At 4008ABE8 len 00015418 (85 KiB): IRAM
I (287) cpu_start: Pro cpu start user code
I (305) spi_flash: detected chip: generic
I (305) spi_flash: flash io: dio
W (305) spi_flash: Detected size(16384k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (316) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (328) uart: queue free spaces: 20

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

Re: Modbus slave

Postby ESP_alisitsyn » Wed Mar 11, 2020 9:52 am

Hi @Chriserke,

In your case the pins IO16, IO17 can be used for UART. The reason for issue is different. I don't know exactly your commit ID (can not get it from your log) of ESP_IDF but it looks like a bug in this particular commit and it was fixed later.
Could you change the line "components/freemodbus/modbus/ascii/mbascii.c", line 424, as below:
  1.         assert( ( eRcvState == STATE_RX_RCV ) || ( eRcvState == STATE_RX_WAIT_EOF )
  2.                         || ( eRcvState == STATE_RX_IDLE ) );
Please try this change and let me know if it helps. Thank you.

Also please be noted that example communication mode (Modbus ASCII) do not match communication mode in your Modbus host tool (Modbus RTU as per your picture).

--
Alex

Chriserke
Posts: 9
Joined: Mon Mar 09, 2020 1:56 pm

Re: Modbus slave

Postby Chriserke » Wed Mar 11, 2020 10:25 am

Hello,

The reboot seems to be fixed. And i can sometimes receive some data like once every 10-20 tries as can be seen in the console.
And ASCii was used to make debugging on the scope easier.

Anyway i'm not sure what the issue is now though.
Perhaps you have some insights as to what could cause this?
EDIT:
There seems to be some faulty readings so perhaps it could be a noise issue?
Below is the output while trying to read the discrete input with a register size of 8.

HOLDING READ: time_stamp(us):709037889, mb_addr:1, type:2, st_address:0x3ffb2fa8, size:10
HOLDING READ: time_stamp(us):743847800, mb_addr:1, type:2, st_address:0x3ffb2fa8, size:10
DISCRETE READ: time_stamp(us):819007536, mb_addr:0, type:64, st_address:0x3ffb2f90, size:0
HOLDING READ: time_stamp(us):848913893, mb_addr:1, type:2, st_address:0x3ffb2fa8, size:10
HOLDING READ: time_stamp(us):951547132, mb_addr:1, type:2, st_address:0x3ffb2fa8, size:10
HOLDING READ: time_stamp(us):986815143, mb_addr:1, type:2, st_address:0x3ffb2fa8, size:10
Attachments
65b0b96c9f3c100db1efa9509ff0d818.png
65b0b96c9f3c100db1efa9509ff0d818.png (139.88 KiB) Viewed 2321 times

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

Re: Modbus slave

Postby ESP_alisitsyn » Wed Mar 11, 2020 2:43 pm

I still do not know the correct commit ID (it is old preliminary version) but goal of change I provided just to check issue. Could you please rebase your ESP-IDF on master? The latest master has all required fixes and ASCII mode shall work just fine. Please let me know the result.

Thanks.

Chriserke
Posts: 9
Joined: Mon Mar 09, 2020 1:56 pm

Re: Modbus slave

Postby Chriserke » Wed Mar 11, 2020 2:55 pm

Hello,

I'm using visual GDB with the release version 4.0.
The official visual GDB support does not go higher than version 4.0 as of now for esp-idf.
So i'll see what i can do but it might not work.

EDIT: I tried the master version (4.1) and the same issue pops up. So i guess ill get back to debugging the data lines for now.
Last edited by Chriserke on Thu Mar 12, 2020 8:02 am, edited 1 time in total.

Who is online

Users browsing this forum: PaulFreund, usulrasolas and 19 guests