Merging the MODBUS_TCP_MODE_XMC47 example project with my own project

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
AlRu_4725236
Level 1
Level 1
First like received First reply posted First question asked

Hello,

I am trying to implement Modbus TCP communications into a project to enable communications between my device and a PLC.

I am able to get the example project working good enough that I can reliably send data to a PLC and receive data from it. However, I am unsure how to merge the example project with my project.

The best I have been able to do so far is shown in the attached project. I have renamed the Modbus program's main() to modbustcp(). I call that from another source file which is where main() now resides. This successfully starts the thread, calls mbtcp_thread() and initializes the Modbus protocol stack, and enters the polling loop before functioning like normal. Of course it is then stuck in that polling loop forever.

So, how can I poll from my main loop instead? I have tried calling eMBPoll() in my loop after calling modbustcp(), however this just results in the thread being terminated after eMBEnable() is called. Whatever I do, unless there is a repeating loop inside mbtcp_thread() after eMBEnable(), the thread is automatically terminated and the program hangs in some for loop elsewhere.

I have tried calling all of the initialization functions inside my main(), but it will not compile that way, as it seems that there needs to exist a function called mbtcp_thread(), which is called (presumably by the stack it self?) sometime after osThreadCreate() is called.

I am very new to microcontroller programming and even newer to implementing communication protocols on such a platform, so please bear with me.

0 Likes
1 Reply
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked

Hi,

Asking some questions for clarity. Have you used MODBUS_TCP_MODE_XMC47 as reference for your code ? This code is developed to be work in an OS environment. Was it working as expected with the PLC  in current OS version? Are you facing the issues only while removing the OS support ? Additionally was it working as expected mbtcp_thread() ? Did you face problems only when you tried to move the polling loop to main loop ?

Best Regards,
Vasanth

0 Likes