Page 1 of 1

Modbus RTU RS485 - Receiving Issue

Posted: Tue Oct 30, 2018 8:02 pm
by George_B
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

Re: Modbus RTU RS485 - Receiving Issue

Posted: Wed Oct 31, 2018 11:32 am
by Benj
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 5135 times

Re: Modbus RTU RS485 - Receiving Issue

Posted: Thu Nov 01, 2018 9:18 am
by George_B
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?

Re: Modbus RTU RS485 - Receiving Issue

Posted: Tue Dec 11, 2018 11:02 am
by George_B
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

Re: Modbus RTU RS485 - Receiving Issue

Posted: Wed Dec 12, 2018 12:42 pm
by Benj
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.

Re: Modbus RTU RS485 - Receiving Issue

Posted: Fri Dec 14, 2018 10:25 am
by George_B
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

Re: Modbus RTU RS485 - Receiving Issue

Posted: Fri Dec 14, 2018 11:54 am
by LeighM
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.