Modbus sample errors- cdc acm


i want to use modbus RTU server sample, ive done everything just like in guide, used proper devicetree, commented line in overlay etc. Downloaded pymodbus with the plugin to have a console working with just commands. And this is what i get everytime: 

Any idea how can i repair it? I want to use sample in my own code, but i cant get it working. Ofc ive changed command to start terminal with ttyACM0. 

  • Hi

    Which version of NCS are you using? 

    Could you show me your build configuration? 

    Do you have any warnings in your build log? 



  • v2.6.1, west worskpace v2.5.2

    (Im inside modbus rtu server folder)

    nrfutil toolchain-manager launch --shell
    west build -b nrf52840dk_nrf52840 -- -DDTC_OVERLAY_FILE=cdc-acm.overlay -DEXTRA_CONF_FILE=overlay-cdc-acm.conf
    west flash

    Initializing shell environment!
    bash-5.1$ west build -b nrf52840dk_nrf52840 -- -DDTC_OVERLAY_FILE=cdc-acm.overlay -DEXTRA_CONF_FILE=overlay-cdc-acm.conf
    -- west build: generating a build system
    Loading Zephyr default modules (Zephyr base (cached)).
    -- Application: /home/hubert/ncs/zephyr/samples/subsys/modbus/rtu_server
    -- CMake version: 3.21.0
    -- Found Python3: /home/hubert/ncs/toolchains/2be090971e/usr/local/bin/python3.9 (found suitable version "3.9.18", minimum required is "3.8") found components: Interpreter 
    -- Cache files will be written to: /home/hubert/.cache/zephyr
    -- Zephyr version: 3.4.99 (/home/hubert/ncs/zephyr)
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf52840dk_nrf52840
    -- Found host-tools: zephyr 0.16.5 (/home/hubert/ncs/toolchains/2be090971e/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.16.5 (/home/hubert/ncs/toolchains/2be090971e/opt/zephyr-sdk)
    -- Found BOARD.dts: /home/hubert/ncs/zephyr/boards/arm/nrf52840dk_nrf52840/nrf52840dk_nrf52840.dts
    -- Found devicetree overlay: cdc-acm.overlay
    -- Found devicetree overlay: cdc-acm.overlay
    -- Generated zephyr.dts: /home/hubert/ncs/zephyr/samples/subsys/modbus/rtu_server/build/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: /home/hubert/ncs/zephyr/samples/subsys/modbus/rtu_server/build/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: /home/hubert/ncs/zephyr/samples/subsys/modbus/rtu_server/build/zephyr/dts.cmake
    Parsing /home/hubert/ncs/zephyr/Kconfig
    Loaded configuration '/home/hubert/ncs/zephyr/samples/subsys/modbus/rtu_server/build/zephyr/.config'
    No change to configuration in '/home/hubert/ncs/zephyr/samples/subsys/modbus/rtu_server/build/zephyr/.config'
    No change to Kconfig header in '/home/hubert/ncs/zephyr/samples/subsys/modbus/rtu_server/build/zephyr/include/generated/autoconf.h'
    CMake Warning at /home/hubert/ncs/zephyr/subsys/usb/device/CMakeLists.txt:22 (message):
      CONFIG_USB_DEVICE_VID has default value 0x2FE3.
      This value is only for testing and MUST be configured for USB products.
    CMake Warning at /home/hubert/ncs/zephyr/subsys/usb/device/CMakeLists.txt:28 (message):
      CONFIG_USB_DEVICE_PID has default value 0x100.
      This value is only for testing and MUST be configured for USB products.
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/hubert/ncs/zephyr/samples/subsys/modbus/rtu_server/build
    -- west build: building application
    [7/7] Linking C executable zephyr/zephyr.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:       62108 B         1 MB      5.92%
                 RAM:       21196 B       256 KB      8.09%
            IDT_LIST:          0 GB         2 KB      0.00%

  • I found out that i always get stuck in

    while (!dtr) {
    		uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr);

    so i always get to the

  • The build log looks fine

    Dzolo2k1 said:

    v2.6.1, west worskpace v2.5.2

    I would strongly recommend that you use the corresponding toolchain to the sdk version. 

    I suspect it might there is something with the uart. The baudrate used in the pymodbus doc do not correspond to the normal baudrate used on nordic devices. 

    I would also suggest disabling mass storage device on your dk as it might cause some issues. 

    Disable mass storage device
    To disable the Mass Storage Device functionality on your Nordic Semiconductor device, you can follow these steps:
    1. Open JLinkExe from a terminal on GNU/Linux or macOS (OS X), or open the "JLink Commander" application on Microsoft Windows.
    2. Type the following command:
    3. Unplug and replug the board. The Mass Storage Device should not appear anymore.




  • I did change baudrate once to 115200 in both example and pymodbus terminal and it didnt work. Ill try to disable mass storage device, but i have a question. What do you mean with corresponding toolchain, im using 2.6.1 according to VSC and nrfutill shell