Transferring data with Modbus RTU

Post and discuss new components that you have created.
Post Reply
SpeedPIC32
Posts: 252
http://meble-kuchenne.info.pl
Joined: Thu Dec 10, 2020 2:35 pm
Has thanked: 36 times
Been thanked: 17 times

Transferring data with Modbus RTU

Post by SpeedPIC32 »

Hello,
I need your help
how do I implement the following code under Modbus RTU?
Slave address 0x01
Function code 0x06
Register address 0x0000
The value for the register e.g. 0x0960
CRC Checksum 0x8FB2 =16Bit Start Preloading a 16-bit register to all 1's =65535

The code is used to set a power supply voltage to 24 volts.

Use a serial interface for this.
The hex values are taken from the operating instructions for the DPH5005 power supply unit.

mfg SpeedPic32

SpeedPIC32
Posts: 252
Joined: Thu Dec 10, 2020 2:35 pm
Has thanked: 36 times
Been thanked: 17 times

Re: Transferring data with Modbus RTU

Post by SpeedPIC32 »

Can the power supply unit be made into a component? Joy-IT JT-DPH5005


Sincerely SpeedPic32
Attachments
JOY-IT_DPH5005_DS-EN.pdf
(295.32 KiB) Downloaded 113 times

SpeedPIC32
Posts: 252
Joined: Thu Dec 10, 2020 2:35 pm
Has thanked: 36 times
Been thanked: 17 times

Re: Transferring data with Modbus RTU

Post by SpeedPIC32 »

Can the power supply unit be made into a component? Joy-IT JT-DPH5005
DPS5005USB.pdf
(1.3 MiB) Downloaded 128 times
Sincerely SpeedPic32

BenR
Matrix Staff
Posts: 1726
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 438 times
Been thanked: 602 times

Re: Transferring data with Modbus RTU

Post by BenR »

Hello,

Are you trying to communicate with a slave device or create a slave device?

Function code 6 is the SetHoldingRegister command for the Master.

This example might help show how things work from the Master point of view.
Modbus_Example.fcfx
(8.79 KiB) Downloaded 146 times

BenR
Matrix Staff
Posts: 1726
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 438 times
Been thanked: 602 times

Re: Transferring data with Modbus RTU

Post by BenR »

The power supply looks interesting, I'll see if I can find some time today to start some macros to drive it to help show you how we might go about creating a component.

BenR
Matrix Staff
Posts: 1726
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 438 times
Been thanked: 602 times

Re: Transferring data with Modbus RTU

Post by BenR »

Here's a simple program with some macros to read/write the output voltage and current.

Modbus_Example_DPH5005.fcfx
(22.44 KiB) Downloaded 137 times

The slave address is assigned via a property and I've exposed a few other Modbus specific properties so you can configure them if exported as a component.

Let us know how you get on.

SpeedPIC32
Posts: 252
Joined: Thu Dec 10, 2020 2:35 pm
Has thanked: 36 times
Been thanked: 17 times

Re: Transferring data with Modbus RTU

Post by SpeedPIC32 »

hello,
unfortunately there are errors
With kind regards
SpeedPic32



Target folder: C:\Users\uwe\Documents\Daten\Flowcode_Projekte
Source name: C:\Users\uwe\Documents\Daten\Flowcode_Projekte\Modbus_Example_DPH5005.fcfx
Device: PIC32.32MZ.32MZ2048EFH100
Generated by: Flowcode v9.2.0.33
Date: Friday, January 28, 2022 15:20:30
Registered to: SpeedPic32 (24146314)
Licence key: ACFPTQ
NOT FOR COMMERCIAL USE
https://www.flowcode.co.uk
Using <IDC USB> user settings for compiler
Launching the compiler...
C:\Program Files (x86)\Flowcode\Compilers\pic32\batch\PIC32compCDC.bat "32MZ2048EFH100" "C:\Users\uwe\Documents\Daten\Flowcode_Projekte\" "Modbus_Example_DPH5005" "32MZ"
Project Modbus_Example_DPH5005
Device 32MZ2048EFH100
Objects Modbus_Example_DPH5005_32MZ2048EFH100
C:\Users\uwe\Documents\Daten\Flowcode_Projekte>xc32-gcc -mprocessor=32MZ2048EFH100 -DMX_USBHS -I"C:\Users\uwe\Documents\Daten\Flowcode_Projekte\." -I"C:\ProgramData\MatrixTSL\FlowcodeV9\CAL\PIC32BIT\USB\CDC" -I"C:\microchip\harmony\v1_11" -I"C:\microchip\harmony\v1_11\framework" -w -c -ffunction-sections -O1 -o "Modbus_Example_DPH5005_32MZ2048EFH100\Modbus_Example_DPH5005.o" "Modbus_Example_DPH5005.c" -DMX_USBHS
Modbus_Example_DPH5005.c: In function 'FCD_05481_cal_uart__ControlPin':
Modbus_Example_DPH5005.c:445:40: error: macro "GET_PORT_MASK" requires 2 arguments, but only 1 given
^
Modbus_Example_DPH5005.c:445:18: error: 'GET_PORT_MASK' undeclared (first use in this function)
Modbus_Example_DPH5005.c:445:18: note: each undeclared identifier is reported only once for each function it appears in
Modbus_Example_DPH5005.c: In function 'FCD_05481_cal_uart__Prv_SimShowWaveform':
Modbus_Example_DPH5005.c:674:29: error: macro "SET_PORT_MASK" requires 3 arguments, but only 2 given
^
Modbus_Example_DPH5005.c:674:4: error: 'SET_PORT_MASK' undeclared (first use in this function)
Modbus_Example_DPH5005.c:685:31: error: macro "SET_PORT_MASK" requires 3 arguments, but only 2 given
^
Modbus_Example_DPH5005.c:690:31: error: macro "SET_PORT_MASK" requires 3 arguments, but only 2 given
// .Data = .Data >> 1
^
Modbus_Example_DPH5005.c:703:29: error: macro "SET_PORT_MASK" requires 3 arguments, but only 2 given
//Code has been optimised out by the pre-processor
^
C:\Program Files (x86)\Flowcode\Compilers\pic32\batch\PIC32compCDC.bat reported error code 0x1
Autoclose turned off

BenR
Matrix Staff
Posts: 1726
Joined: Mon Dec 07, 2020 10:06 am
Has thanked: 438 times
Been thanked: 602 times

Re: Transferring data with Modbus RTU

Post by BenR »

Hello,

Without seeing your project I'm just guessing but it looks like some of the pin connections for the Modbus component are not defined correctly.

SpeedPIC32
Posts: 252
Joined: Thu Dec 10, 2020 2:35 pm
Has thanked: 36 times
Been thanked: 17 times

Re: Transferring data with Modbus RTU

Post by SpeedPIC32 »

Hello.
That was my mistake.
I saved the project in a new folder, hence the error.
now it runs. Thanks

With kind regards
SpeedPic32

Post Reply