Modbus direction control

For general Flowcode discussion that does not belong in the other sections.
Post Reply
RGV250
Posts: 264
http://meble-kuchenne.info.pl
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 23 times
Been thanked: 30 times

Modbus direction control

Post by RGV250 »

Hi,
I thought it best to start a new topic so I don't clutter the other one up.
I have been having a lot of issues with Modbus RS485, I am getting closer but now think there is an issue with the direction control.
I now have the send message as it should be but I get no response from the slave. Instead of the device I hooked up a USB/RS485 converter and Modbus slave software. This showed it was only getting part of the message, the logic analyser showed it was sending it all but it looks like the data direction is being changed early. I put the link for the direction to VCC so it was high permanently and the slave receives the whole message which leads me to believe there is an issue with the direction software.

Here is the slave showing part message.
Modbus slave 1.jpg
Modbus slave 1.jpg (80.83 KiB) Viewed 1323 times
Here is the logic analyser showing the whole message being sent but the direction changes after the function byte.
Modbus logic.jpg
Modbus logic.jpg (52.67 KiB) Viewed 1323 times
Here is the slave showing the whole message received and a simulated response.
Modbus slave 2.jpg
Modbus slave 2.jpg (88.8 KiB) Viewed 1323 times
The project is here if you need it, 2nd to last post. viewtopic.php?f=3&t=1348

Regards,
Bob

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: Modbus direction control

Post by BenR »

Hi Bob,

I beleive I've seen this before on PIC16/32 hardware and has to do with UART Tx bytes not being transmitted immediatley or being queued up to be sent. The ESP certainly does this. So I've now added a check in the Modbus Master component to wait until the transmit buffer is empty before switching the RS485 DDR state.

Update is now available via the library updates.

Hopefully this helps.

RGV250
Posts: 264
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 23 times
Been thanked: 30 times

Re: Modbus direction control

Post by RGV250 »

Hi Ben,
Update, in my test with the software slave it appears to work but something strange is happening now.
The message is sent as expected but there is an extra byte on the end (circled), then there is also another request that I have no idea where that is coming from. This is happening on evert message where it did not before?
modbus new response.jpg
modbus new response.jpg (61.92 KiB) Viewed 1289 times
I am not sure when I will be able to try with the actual slave device, probably the weekend but this should not be any different as this is sent data.

Bob

BenR
Matrix Staff
Posts: 1707
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 435 times
Been thanked: 598 times

Re: Modbus direction control

Post by BenR »

Hi Bob,

I can't spot anything in your program that you showed that would account for the second message, not sure where that one is coming from?

Glad it's working better for you now though.

RGV250
Posts: 264
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 23 times
Been thanked: 30 times

Re: Modbus direction control

Post by RGV250 »

Hi Ben,
I did try it with the actual hardware and it did not work, I will need to hook the logic analyser up to see what is happening there.
I have also just collected some transcievers that do not need a direction control so will update later.

Bob

RGV250
Posts: 264
Joined: Sat Mar 19, 2022 4:53 pm
Has thanked: 23 times
Been thanked: 30 times

Re: Modbus direction control

Post by RGV250 »

Hi Ben,
The issue is partly resolved, I changed the MAX485 module to one that does not require a direction input. This worked straight away so it appears there is still an issue with the updated change. When I had the logic analyser on it I think the extra transmitted byte was the issue.
When I have played around with the webserver and getting the data from the module into it I will see if I can put the other MAX485 transceiver back and get screen grabs so we can see what each looks like.

Regards,
Bob

Post Reply