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
Modbus RTU RS485 - Receiving Issue
Moderator: Benj
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Modbus RTU RS485 - Receiving Issue
Hi George,
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.
0x01 + 0x04 + 0x00 + 0x00 + 0x00 + 0x08 + 0xF1 + 0xCC
The values here are identical, the only difference is the hex notation. Flowcode needs valued to be entered as 0xXX to qualify as hex.01 04 00 00 00 08 F1 CC
On a microcontroller everything is in Binary, hex and decimal are simply easier to read variations of the binary numbers.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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 128
- Joined: Wed Jul 04, 2012 11:21 pm
- Location: Greece
- Has thanked: 51 times
- Been thanked: 19 times
- Contact:
Re: Modbus RTU RS485 - Receiving Issue
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?
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 (11.3 KiB) Viewed 5138 times
-
- MODBUS.jpg (49.9 KiB) Viewed 5138 times
-
- Posts: 128
- Joined: Wed Jul 04, 2012 11:21 pm
- Location: Greece
- Has thanked: 51 times
- Been thanked: 19 times
- Contact:
Re: Modbus RTU RS485 - Receiving Issue
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
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
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Modbus RTU RS485 - Receiving Issue
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.Now the issue that i am facing is regarding the receiving data using 2 stop bits.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 128
- Joined: Wed Jul 04, 2012 11:21 pm
- Location: Greece
- Has thanked: 51 times
- Been thanked: 19 times
- Contact:
Re: Modbus RTU RS485 - Receiving Issue
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 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
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 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 256 times
-
- Modbus_RTU.fcfx
- (30.73 KiB) Downloaded 270 times
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
- Contact:
Re: Modbus RTU RS485 - Receiving Issue
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.
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.