Hello
I have a test program running Modbus slave, and it seems to be working ok reading registers. However its a little odd and perhaps it just needs a little explanation.
I have set holding registers with addresses 1 through to 5 with some values. When I read the registers I get the correct responce but always the register address above the one I have requested. Ie, if I request the data from register 1, I get the data stored in register 2. This carries on for all regesters up to 5. This means I am missing register 1.
I get this if I read jsut one register at a time all all 5 resisters, see below:
I have also attached hte slave code.
Thanks
Modbus Slave
-
- Flowcode V4 User
- Posts: 288
- Joined: Wed Nov 02, 2011 11:15 pm
- Has thanked: 29 times
- Been thanked: 30 times
- Contact:
-
- Flowcode V4 User
- Posts: 288
- Joined: Wed Nov 02, 2011 11:15 pm
- Has thanked: 29 times
- Been thanked: 30 times
- Contact:
Re: Modbus Slave
Hello
Also found another potential issue...
When I select the RS485 bus and select the data directional pin I get compiler errors (and select the pin A10). This is the only change I make before I get any compile errors.
http://www.matrixtsl.com
Launching the compiler...
C:\Program Files (x86)\Flowcode\Common\Compilers\pic16\batchfiles\pic16_C30_comp.bat "C:\Users\pc\ZIKODR~1\ZIKODR~1\QUALIT~1\SPECIF~1\ALLSPE~1\PROGRA~1\VERSIO~2\ZDBL45LS3.11" "C:\Users\pc\ZIKODR~1\ZIKODR~1\QUALIT~1\SPECIF~1\ALLSPE~1\PROGRA~1\VERSIO~2\" "33EP32MC504"
C:\Users\pc\QUALIT~1\SPECIF~1\ALLSPE~1\PROGRA~1\VERSIO~2>xc16-gcc -c -mcpu="33EP32MC504" -omf=coff -funsigned-char -fno-short-double -Os -I"C:\PROGRA~2\Flowcode\Common\COMPIL~1\pic16\BATCHF~1\..\support\h" -I"C:\PROGRA~2\Flowcode\Common\COMPIL~1\pic16\BATCHF~1\" -std=gnu99 "C:\Users\pc\QUALIT~1\SPECIF~1\ALLSPE~1\PROGRA~1\VERSIO~2\ZDBL45LS3.11".c -o "C:\Users\pc\ZIKODR~1\ZIKODR~1\QUALIT~1\SPECIF~1\ALLSPE~1\PROGRA~1\VERSIO~2\LS3.11".o
Options have been disabled due to restricted license
Visit http://www.microchip.com/ to purchase a new key.
C:\Users\pc\L45LS3.11.c: In function 'FCD_04c01_ModbusSlave1__CheckForIncoming':
C:\Users\pc\LS3.11.c12: error: 'U3STAbits' undeclared (first use in this function)
C:\Users\pc\LS3.11.c12: note: each undeclared identifier is reported only once for each function it appears in
C:\Users\pc\LS3.11.c12: error: 'U4STAbits' undeclared (first use in this function)
Error returned from [xc16-gcc.exe]
C:\Program Files (x86)\Flowcode\Common\Compilers\pic16\batchfiles\pic16_C30_comp.bat reported error code 1
FINISHED
Thanks
Also found another potential issue...
When I select the RS485 bus and select the data directional pin I get compiler errors (and select the pin A10). This is the only change I make before I get any compile errors.
http://www.matrixtsl.com
Launching the compiler...
C:\Program Files (x86)\Flowcode\Common\Compilers\pic16\batchfiles\pic16_C30_comp.bat "C:\Users\pc\ZIKODR~1\ZIKODR~1\QUALIT~1\SPECIF~1\ALLSPE~1\PROGRA~1\VERSIO~2\ZDBL45LS3.11" "C:\Users\pc\ZIKODR~1\ZIKODR~1\QUALIT~1\SPECIF~1\ALLSPE~1\PROGRA~1\VERSIO~2\" "33EP32MC504"
C:\Users\pc\QUALIT~1\SPECIF~1\ALLSPE~1\PROGRA~1\VERSIO~2>xc16-gcc -c -mcpu="33EP32MC504" -omf=coff -funsigned-char -fno-short-double -Os -I"C:\PROGRA~2\Flowcode\Common\COMPIL~1\pic16\BATCHF~1\..\support\h" -I"C:\PROGRA~2\Flowcode\Common\COMPIL~1\pic16\BATCHF~1\" -std=gnu99 "C:\Users\pc\QUALIT~1\SPECIF~1\ALLSPE~1\PROGRA~1\VERSIO~2\ZDBL45LS3.11".c -o "C:\Users\pc\ZIKODR~1\ZIKODR~1\QUALIT~1\SPECIF~1\ALLSPE~1\PROGRA~1\VERSIO~2\LS3.11".o
Options have been disabled due to restricted license
Visit http://www.microchip.com/ to purchase a new key.
C:\Users\pc\L45LS3.11.c: In function 'FCD_04c01_ModbusSlave1__CheckForIncoming':
C:\Users\pc\LS3.11.c12: error: 'U3STAbits' undeclared (first use in this function)
C:\Users\pc\LS3.11.c12: note: each undeclared identifier is reported only once for each function it appears in
C:\Users\pc\LS3.11.c12: error: 'U4STAbits' undeclared (first use in this function)
Error returned from [xc16-gcc.exe]
C:\Program Files (x86)\Flowcode\Common\Compilers\pic16\batchfiles\pic16_C30_comp.bat reported error code 1
FINISHED
Thanks
-
- Flowcode V4 User
- Posts: 288
- Joined: Wed Nov 02, 2011 11:15 pm
- Has thanked: 29 times
- Been thanked: 30 times
- Contact:
Re: Modbus Slave
Hello Again...
I apologise for the multiple questions, however I am still learning MODbus and need to know if what I am seeing should be correct.
Here we have the master (PC software) writing a 0 to to the coil in address 1, and the PIC replies OK with a duplicate of the of the transmitted message.
But then, when the master sends a 1 to the coil in address 1, the PIC still responds with the saying the coil is empty (see below).
Thanks
I apologise for the multiple questions, however I am still learning MODbus and need to know if what I am seeing should be correct.
Here we have the master (PC software) writing a 0 to to the coil in address 1, and the PIC replies OK with a duplicate of the of the transmitted message.
But then, when the master sends a 1 to the coil in address 1, the PIC still responds with the saying the coil is empty (see below).
Thanks
- 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 Slave
Hello,
Modbus addresses are indexed from 0. i.e. address 0 is register 1. Hope this helps to explain things.I have set holding registers with addresses 1 through to 5 with some values. When I read the registers I get the correct responce but always the register address above the one I have requested. Ie, if I request the data from register 1, I get the data stored in register 2. This carries on for all regesters up to 5. This means I am missing register 1.
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
-
- Flowcode V4 User
- Posts: 288
- Joined: Wed Nov 02, 2011 11:15 pm
- Has thanked: 29 times
- Been thanked: 30 times
- Contact:
Re: Modbus Slave
Hi Ben
Yeah, I knew this. I was just hoping to keep the 0x00 registers blank and start from 1. The problem I am having is that if I request the data from register 1, I get the data from register 2. And if I request the data from register 2 I get the data from register 3.
The data I have stored in the slave holding regisers on the PIC are:
Register 1 = 12
Register 2 = 23
Register 3 = 34
Register 4 = 45
Register 5 = 56
For the Modbus issue.jpg below, on the first line we have:
Sent from PC
1C = Slave address
03 = Function code - Read holding registers
00 01 = Read start register
00 01 = Number of read registers
D6 47 = CRC
I then get a responce on line 2 from the PIC
1C = Slave Address
02 = Byte Count
00 17 = Register Values
14 48 = CRC
So, when I read register 1 I ahve getting the 0x17 (23) which I had stored in Register 2. This continues when I attempt to read all the registers.
Thanks
Yeah, I knew this. I was just hoping to keep the 0x00 registers blank and start from 1. The problem I am having is that if I request the data from register 1, I get the data from register 2. And if I request the data from register 2 I get the data from register 3.
The data I have stored in the slave holding regisers on the PIC are:
Register 1 = 12
Register 2 = 23
Register 3 = 34
Register 4 = 45
Register 5 = 56
For the Modbus issue.jpg below, on the first line we have:
Sent from PC
1C = Slave address
03 = Function code - Read holding registers
00 01 = Read start register
00 01 = Number of read registers
D6 47 = CRC
I then get a responce on line 2 from the PIC
1C = Slave Address
02 = Byte Count
00 17 = Register Values
14 48 = CRC
So, when I read register 1 I ahve getting the 0x17 (23) which I had stored in Register 2. This continues when I attempt to read all the registers.
Thanks
-
- Flowcode V4 User
- Posts: 288
- Joined: Wed Nov 02, 2011 11:15 pm
- Has thanked: 29 times
- Been thanked: 30 times
- Contact:
Re: Modbus Slave
Hello
I'm the second post above I have compiling issues when I use the RS485 bus and set the data direction pin.
I am using the dsPIC33EP32MC504, does anyone have any advice on getting this working? I have filled in all the component proporties.
Thanks
I'm the second post above I have compiling issues when I use the RS485 bus and set the data direction pin.
I am using the dsPIC33EP32MC504, does anyone have any advice on getting this working? I have filled in all the component proporties.
Thanks
- 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 Slave
Hello,
Thanks for letting us know of the problem.
I have now managed to track down and fix the issue and the latest fixed files are now available via the Help -> check for updates menu.
Let us know how you get on.
Thanks for letting us know of the problem.
I have now managed to track down and fix the issue and the latest fixed files are now available via the Help -> check for updates menu.
Let us know how you get on.
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
-
- Flowcode V4 User
- Posts: 288
- Joined: Wed Nov 02, 2011 11:15 pm
- Has thanked: 29 times
- Been thanked: 30 times
- Contact: