Modbus RTU RS485 - Receiving Issue

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

George_B
Posts: 88
Joined: Wed Jul 04, 2012 11:21 pm
Has thanked: 37 times
Been thanked: 12 times
Contact:

Modbus RTU RS485 - Receiving Issue

Postby George_B » Tue Oct 30, 2018 8:02 pm

Hello, i hope you are all good!

I have to read a power meter (Voltage - Amperes - Watts etc.) using Modbus RTU.

In order to get some level of experience and understand things better, i first installed a modbus terminal software to observe the communication structure. I understand a few things and i was able aftes a few minutes to have a reply from the power meter with all the information that i want.

I then moved to flowcode, to write a simple program, to poll data from power meter since i knew the structure of the polling data.

I was a bit struggling to send the commands with the correct format because the power meter needs to receive hex values in the form :

0x01 + 0x04 + 0x00 + 0x00 + 0x00 + 0x08 + 0xF1 + 0xCC


I observed what was the form of the data, that the modbus terminal software was sending to power meter and that was of the form:

01 04 00 00 00 08 F1 CC

After a little search in the forum, i found how to send the hex value of 0x00 successfully.

Then i had a problem because of the 2 STOP Bits that the power meter protocol uses. To overcome this i used a small delay of 1ms after each command so it will be considered as 2 stop bits from power meter.

I finally managed to send the correct request data to power meter and it was sending a reply with all the data that i need.

My problem is how to read those data since the form of them is in hex and i have never done this again. I need to read the incoming data and show them on the LCD.

I have attached the flowcode 7 program that i used to poll data from power meter.

Could anyone give me a hand with this on please?

Thanks in advance

George
Attachments
Modbus_RTU.fcfx
(13.6 KiB) Downloaded 82 times

User avatar
Benj
Matrix Staff
Posts: 14674
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4659 times
Been thanked: 4283 times
Contact:

Re: Modbus RTU RS485 - Receiving Issue

Postby Benj » Wed Oct 31, 2018 11:32 am

Hi George,

0x01 + 0x04 + 0x00 + 0x00 + 0x00 + 0x08 + 0xF1 + 0xCC


01 04 00 00 00 08 F1 CC


The values here are identical, the only difference is the hex notation. Flowcode needs valued to be entered as 0xXX to qualify as hex.

My problem is how to read those data since the form of them is in hex and i have never done this again. I need to read the incoming data and show them on the LCD.


On a microcontroller everything is in Binary, hex and decimal are simply easier to read variations of the binary numbers.

You could print out the value on the LCD in Decimal or you could use the NumberToHex$ function in the calculation icon to convert a numeric variable into a hexadecimal string you can print to the LCD.

NumToHexStr.jpg
NumToHexStr.jpg (51.32 KiB) Viewed 2104 times

George_B
Posts: 88
Joined: Wed Jul 04, 2012 11:21 pm
Has thanked: 37 times
Been thanked: 12 times
Contact:

Re: Modbus RTU RS485 - Receiving Issue

Postby George_B » Thu Nov 01, 2018 9:18 am

Hello Benj, thank you for your reply.

I am still confused and wondering how to receive and handle the incoming data from modbus slave.

Using Modbus Poll software i managed to communicate with the slave device and get the expected data.(see pictures)

The only options in flowcode for getting data through UART is to receive as string or receive as char.

If i use the option "receive as string" what would be the next step to convert those data to a format that i will be able to show on LCD?
Attachments
Screenshot_3.jpg
Screenshot_3.jpg (11.3 KiB) Viewed 2090 times
MODBUS.jpg
MODBUS.jpg (49.9 KiB) Viewed 2090 times

George_B
Posts: 88
Joined: Wed Jul 04, 2012 11:21 pm
Has thanked: 37 times
Been thanked: 12 times
Contact:

Re: Modbus RTU RS485 - Receiving Issue

Postby George_B » Tue Dec 11, 2018 11:02 am

Hello, i manage to request the data correctly from Power Meter.

Now the issue that i am facing is regarding the receiving data using 2 stop bits.

Is there any idea how to achieve this? I am using Rx interrupt to receive the incomming data.


Thank in advance!

George

User avatar
Benj
Matrix Staff
Posts: 14674
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4659 times
Been thanked: 4283 times
Contact:

Re: Modbus RTU RS485 - Receiving Issue

Postby Benj » Wed Dec 12, 2018 12:42 pm

Now the issue that i am facing is regarding the receiving data using 2 stop bits.


You shouldn't have to do anything and this will work as is. 2 stop bits is more a problem for the transmitter than the receiver.

George_B
Posts: 88
Joined: Wed Jul 04, 2012 11:21 pm
Has thanked: 37 times
Been thanked: 12 times
Contact:

Re: Modbus RTU RS485 - Receiving Issue

Postby George_B » Fri Dec 14, 2018 10:25 am

Hello Benj, thank you for your reply.

I am still trying to communicate with the Power Meter with no luck.

The simulation in Proteus gives me correct results but in real hardware there is a problem in the reception of the Power Meter data.

The attached File "Modbus_RTU" (Flowcode 7 Version) shows the firmware that i run in Proteus Simulation and is working fine.

The SIM_modbus file is the Proteus (version 8) file used for simulation.


I can't figure out why is this happening and the data are not received correctly in microcontroller.


Any help would be appreciated.

George
Attachments
SIM_modbus.rar
(17.25 KiB) Downloaded 71 times
Modbus_RTU.fcfx
(30.73 KiB) Downloaded 79 times

User avatar
LeighM
Matrix Staff
Posts: 2008
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 480 times
Been thanked: 688 times
Contact:

Re: Modbus RTU RS485 - Receiving Issue

Postby LeighM » Fri Dec 14, 2018 11:54 am

Hi,
You would be best to use character receive in the interrupt, not string receive.
Increment an index in your receive buffer for each character received,
or use the Circular Buffer component.