Using modbus from verdin IMX8MP Q 8GB

Hi,

Is there any example of modbus for verdin?
I need to use modbus protocol in UART (RS485)
UART (Linux) | Toradex Developer Center
I used

ls -l /dev/verdin-uart*

image

stty -F /dev/verdin-uart1 115200
image

I tried with wrong pin

it is working now

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


The context provided does not include specific information or examples about using the Modbus protocol with the Verdin iMX8M Plus. You may need to refer to additional resources or documentation specific to Modbus implementation on Torizon or the Verdin family.

Please, also check if these links can help you solve your problem:

Page 76 - Toradex Community.

Hello @khaled.hassan,

It is good to know you got this working, thanks for the update.

Best Regards,
Bruno

Hi I tried to use below code

#include <termios.h>

int main() {
struct termios tty;
int fd;
int flags = O_RDWR | O_NOCTTY | O_NONBLOCK;

fd = open("/dev/verdin-uart1", flags);

tcgetattr(fd, &tty);

tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8;
tty.c_cflag |= B115200;

if (tcsetattr (fd, TCSANOW, &tty) != 0)
{
    fprintf (stderr, "error %d from tcsetattr", errno);
    return -1;
}

return 0;

}

But I am getting following error
=thread-group-added,id=“i1” GNU gdb (Debian 13.1-3) 13.1 Copyright (C) 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type “show copying” and “show warranty” for details. This GDB was configured as “aarch64-linux-gnu”. Type “show configuration” for configuration details. For bug reporting instructions, please see: https://www.gnu.org/software/gdb/bugs/. Find the GDB manual and other documentation resources online at: http://www.gnu.org/software/gdb/documentation/. For help, type “help”. Type “apropos word” to search for commands related to “word”. Warning: Debuggee TargetArchitecture not detected, assuming x86_64. =cmd-param-changed,param=“pagination”,value=“off”

[Thread debugging using libthread_db enabled]

Using host libthread_db library “/lib/aarch64-linux-gnu/libthread_db.so.1”.

Breakpoint 1, main () at /home/torizon/app/src/main.cpp:16

Loaded ‘/lib/ld-linux-aarch64.so.1’. Symbols loaded.

Loaded ‘/lib/aarch64-linux-gnu/libstdc++.so.6’. Symbols loaded.

Loaded ‘/lib/aarch64-linux-gnu/libc.so.6’. Symbols loaded.

Loaded ‘/lib/aarch64-linux-gnu/libm.so.6’. Symbols loaded.

Loaded ‘/lib/aarch64-linux-gnu/libgcc_s.so.1’. Symbols loaded.

[Inferior 1 (process 21) exited with code 0377]

The program ‘/home/torizon/app/modbus’ has exited with code 377 (0x00000179).

Hi it worked just needed to add below in docker-compose.yml
devices:
- “/dev/verdin-uart1:/dev/verdin-uart1”

Hello @khaled.hassan,

Thanks for the update.

You are correct, when using specific devices from the host system they need to be added to the container.

If you want to learn more about it, please see our pages about Peripheral Access on Torizon: Best Practices with Peripheral Access | Toradex Developer Center

Best Regards,
Bruno

Hi Bruno,

It just worked by normally after doing that change. Thanks.

1 Like