espressif / esp-modbus

ESP-Modbus - the officially suppported library for Modbus protocol (serial RS485 + TCP over WiFi or Ethernet).
Apache License 2.0
117 stars 55 forks source link

modbus rtu slave stack (IDFGH-11750) #46

Closed kush930 closed 10 months ago

kush930 commented 11 months ago

Hi all,

I want to build esp-modbus source on my machine x86 linux os , I cloned successfully master branch from link- https://github.com/espressif/esp-modbus.git , but here i am not getting proper idea how to compile and install the source.

if anyone knows, can anyone guide me or suggest me, how to build source.

T&R Kush Kumar

alisitsyn commented 11 months ago

Hi Kush Kumar,

In order to build the esp-modbus examples you need to install esp-idf framework and build tools and utils. The esp-modbus component will be installed automatically by component manager. Please follow the steps below to accomplish this:

  1. Follow the guide to install esp-idf and tools and start simple helloworld application from esp-idf framework. All information on how to do this is included in the guide link above.
  2. Prepare as an example the ESP32-DevKitC, but other boards can be used as well (two boards for master and slave example). Just open the terminal application, connect your board to usb port of the computer and type commands:
    cd $IDF_PATH/examples/get-started/hello_world
    idf.py set-target esp32
    idf.py build
    idf.py flash monitor

    Make sure the application is built successfully and last step flashes the application to the board.

  3. Prepare esp32 boards that will be used to check the modbus communication. In order to use RTU communication you need to buy:
  4. Build the official esp-idf Modbus master example. Go to the folder $IDF_PATH/examples/protocols/modbus/serial/mb_master and follow the readme.md file which describes how to connect the RS485 adapter to your ESP32 board. Then build and flash the application in your terminal
    $IDF_PATH/examples/protocols/modbus/serial/mb_master
    idf.py menuconfig

    image, set the options as on the picture and then build the application, connect your ESP32 board to USB port of your PC:

    $IDF_PATH/examples/protocols/modbus/serial/mb_master
    idf.py build
    idf.py flash monitor
  5. Follow the steps above for the Modbus slave project: $IDF_PATH/examples/protocols/modbus/serial/mb_slave. The configuration options idf.py menuconfig: image
    $IDF_PATH/examples/protocols/modbus/serial/mb_slave
    idf.py build 
    idf.py flash monitor
  6. Connect Master board RS485 adapter to Slave board RS485 adapter signals A->A, B->B.
  7. Reset Slave board and then Master board and make sure they can communicate each other over RS485. Make sure you connected the pins of ESP32 board to RS485 adapters correctly as described in readme.md file of master and slave project accordingly. slave log:
    
    rst:0x1 (POWERON_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:0x3fff0030,len:7172
    load:0x40078000,len:15532
    load:0x40080400,len:4
    0x40080400: _init at ??:?

load:0x40080404,len:3904 entry 0x40080640 I (28) boot: ESP-IDF v5.3-dev-1123-g854d2646908 2nd stage bootloader I (28) boot: compile time Dec 21 2023 11:50:51 I (30) boot: Multicore bootloader I (34) boot: chip revision: v1.0 I (38) boot.esp32: SPI Speed : 40MHz I (43) boot.esp32: SPI Mode : DIO I (47) boot.esp32: SPI Flash Size : 2MB I (52) boot: Enabling RNG early entropy source... 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) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=0d388h ( 54152) map I (122) esp_image: segment 1: paddr=0001d3b0 vaddr=3ffb0000 size=0248ch ( 9356) load I (125) esp_image: segment 2: paddr=0001f844 vaddr=40080000 size=007d4h ( 2004) load I (128) esp_image: segment 3: paddr=00020020 vaddr=400d0020 size=18d3ch (101692) map I (171) esp_image: segment 4: paddr=00038d64 vaddr=400807d4 size=0ea08h ( 59912) load I (202) boot: Loaded app from partition at offset 0x10000 I (202) boot: Disabling RNG early entropy source... I (213) cpu_start: Multicore app I (222) cpu_start: Pro cpu start user code I (222) cpu_start: cpu freq: 160000000 Hz I (222) cpu_start: Application information: I (225) cpu_start: Project name: modbus_slave I (231) cpu_start: App version: v5.3-dev-1123-g854d2646908 I (237) cpu_start: Compile time: Dec 21 2023 11:50:48 I (243) cpu_start: ELF file SHA256: 65400a65d... I (249) cpu_start: ESP-IDF: v5.3-dev-1123-g854d2646908 I (255) cpu_start: Min chip rev: v0.0 I (260) cpu_start: Max chip rev: v3.99 I (265) cpu_start: Chip rev: v1.0 I (270) heap_init: Initializing. RAM available for dynamic allocation: I (277) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM I (283) heap_init: At 3FFB32C8 len 0002CD38 (179 KiB): DRAM I (289) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM I (296) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM I (302) heap_init: At 4008F1DC len 00010E24 (67 KiB): IRAM I (310) spi_flash: detected chip: generic I (313) spi_flash: flash io: dio W (317) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header. I (331) main_task: Started on CPU0 I (341) main_task: Calling app_main() I (341) uart: queue free spaces: 20 I (341) SLAVE_TEST: Modbus slave stack initialized. I (341) SLAVE_TEST: Start modbus test... I (1131) SLAVE_TEST: HOLDING READ (821807 us), ADDR:0, TYPE:2, INST_ADDR:0x3ffb2f6c, SIZE:2 I (1141) SLAVE_TEST: INPUT READ (831966 us), ADDR:2, TYPE:8, INST_ADDR:0x3ffb2cf8, SIZE:2 I (1151) SLAVE_TEST: HOLDING READ (842156 us), ADDR:2, TYPE:2, INST_ADDR:0x3ffb2f70, SIZE:2 I (1161) SLAVE_TEST: INPUT READ (852338 us), ADDR:4, TYPE:8, INST_ADDR:0x3ffb2cfc, SIZE:2 I (1171) SLAVE_TEST: HOLDING READ (862568 us), ADDR:4, TYPE:2, INST_ADDR:0x3ffb2f74, SIZE:2 I (1181) SLAVE_TEST: HOLDING READ (872771 us), ADDR:10, TYPE:2, INST_ADDR:0x3ffb2f80, SIZE:58 I (1201) SLAVE_TEST: HOLDING WRITE (899572 us), ADDR:10, TYPE:1, INST_ADDR:0x3ffb2f80, SIZE:58 ...................

Master log:

I (29) boot: ESP-IDF v5.3-dev-1123-g854d2646908 2nd stage bootloader I (29) boot: compile time Dec 21 2023 11:50:23 I (31) boot: Multicore bootloader I (35) boot: chip revision: v1.0 I (39) boot.esp32: SPI Speed : 40MHz I (43) boot.esp32: SPI Mode : DIO I (48) boot.esp32: SPI Flash Size : 2MB I (52) boot: Enabling RNG early entropy source... I (58) boot: Partition Table: I (61) boot: ## Label Usage Type ST Offset Length I (69) boot: 0 nvs WiFi data 01 02 00009000 00006000 I (76) boot: 1 phy_init RF data 01 01 0000f000 00001000 I (84) boot: 2 factory factory app 00 00 00010000 00100000 I (91) boot: 3 coredump Unknown data 01 03 00110000 00010000 I (98) boot: End of partition table I (103) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=0eab0h ( 60080) map I (132) esp_image: segment 1: paddr=0001ead8 vaddr=3ffb0000 size=01540h ( 5440) load I (134) esp_image: segment 2: paddr=00020020 vaddr=400d0020 size=1b6b4h (112308) map I (176) esp_image: segment 3: paddr=0003b6dc vaddr=3ffb1540 size=0147ch ( 5244) load I (178) esp_image: segment 4: paddr=0003cb60 vaddr=40080000 size=0fdc8h ( 64968) load I (215) boot: Loaded app from partition at offset 0x10000 I (215) boot: Disabling RNG early entropy source... I (227) cpu_start: Multicore app I (236) cpu_start: Pro cpu start user code I (236) cpu_start: cpu freq: 160000000 Hz I (236) cpu_start: Application information: I (239) cpu_start: Project name: modbus_master I (244) cpu_start: App version: v5.3-dev-1123-g854d2646908 I (251) cpu_start: Compile time: Dec 21 2023 11:50:20 I (257) cpu_start: ELF file SHA256: 9f763fab7e8a4283... I (263) cpu_start: ESP-IDF: v5.3-dev-1123-g854d2646908 I (269) cpu_start: Min chip rev: v0.0 I (274) cpu_start: Max chip rev: v3.99 I (279) cpu_start: Chip rev: v1.0 I (284) heap_init: Initializing. RAM available for dynamic allocation: I (291) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM I (297) heap_init: At 3FFB41A0 len 0002BE60 (175 KiB): DRAM I (303) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM I (310) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM I (316) heap_init: At 4008FDC8 len 00010238 (64 KiB): IRAM I (324) spi_flash: detected chip: generic I (327) spi_flash: flash io: dio W (331) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header. I (346) main_task: Started on CPU0 I (356) main_task: Calling app_main() I (356) uart: queue free spaces: 20 I (406) MASTER_TEST: Modbus master stack initialized... I (506) MASTER_TEST: Start modbus test... E (706) MB_CONTROLLER_MASTER: mbc_master_get_parameter(73): Master get parameter failure, error=(0x107) (ESP_ERR_TIMEOUT). E (706) MASTER_TEST: Characteristic #0 (Data_channel_0) read fail, err = 0x107 (ESP_ERR_TIMEOUT). I (716) MASTER_TEST: Characteristic #1 Humidity_1 (%rH) value = 1.340000 (0x3fab851f) read successful. I (726) MASTER_TEST: Characteristic #2 Temperature_1 (C) value = 2.340000 (0x4015c28f) read successful. I (736) MASTER_TEST: Characteristic #3 Humidity_2 (%rH) value = 2.560000 (0x4023d70a) read successful. I (746) MASTER_TEST: Characteristic #4 Temperature_2 (C) value = 3.560000 (0x4063d70a) read successful. I (756) MASTER_TEST: Characteristic #5 Humidity_3 (%rH) value = 3.780000 (0x4071eb85) read successful. I (776) MASTER_TEST: Characteristic #6 Test_regs () value = (0x0) read successful. I (796) MASTER_TEST: Characteristic #6 Test_regs () value = (0xaaaaaaaa), write successful. I (796) MASTER_TEST: Characteristic #7 RelayP1 (on/off) value = OFF (0x15) read successful. I (806) MASTER_TEST: Characteristic #8 RelayP2 (on/off) value = OFF (0x2a) read successful. I (816) MASTER_TEST: Characteristic #9 DiscreteInpP1 (on/off) value = OFF (0x15) read successful. I (1316) MASTER_TEST: Characteristic #0 Data_channel_0 (Volts) value = 1.120000 (0x3f8f5c29) read successful. I (1316) MASTER_TEST: Characteristic #1 Humidity_1 (%rH) value = 1.540000 (0x3fc51eb9) read successful. I (1326) MASTER_TEST: Characteristic #2 Temperature_1 (C) value = 2.340000 (0x4015c28f) read successful. .............



Let me know if you have issues with this.
alisitsyn commented 10 months ago

@kush930 , Do you have any update on this? If the issue is solved, please close the ticket. Thanks.

alisitsyn commented 10 months ago

The issue is closed. Feel free to reopen.