Page 1 of 1

Modbus problems

Posted: Sat Feb 24, 2018 4:03 pm
by Walbeek
Hi there,

I have a PIC 16F1936 that I want to use as a Modbus Master.
A LCD is connected to the PIC, together with a MAX485 and some pushbuttons.
I have tested all kinds of communication but I can't get the communication working.
I have inserted a simple program with the instruction "read coil status" every second.
The program is attached below.

Settings are:
Slave ID = 1
Coil address = 0
Number of coils = 4
Functioncode of "Read coil status" should be 1.

According Modbus specs, the software should send 01 (slave), 01 (function), 00, 00, (coil), 04,00 (number) and checksum.
When the simmulation runs, Flowcode shows that the following code is send:
ReadCoilStatus -> SlaveID:1 FunctionCode:1 Address:0 CoilCount:4 CRC:0xc93d

I use a Modbus sniffer that is called Modsim64.
I have connected this to the RS484 Modbus-port and the software is running.
The software shows traffic on the Modbus port.

The software receives 06, 06, 00, 00, 60, e6, 98, 18 (hex) or 006, 006, 000, 000, 000, 096, 230, 152, 024 (dec)
What is going wrong? please let me know if you have any suggestions.

Rinie

Re: Modbus problems

Posted: Sun Feb 25, 2018 9:55 am
by EtsDriver
Using looped back serial port and slave simulator, i got traffic correctly, but simulations hangs on this after slave sends reply... But data looks correct.
I dont have any hardware at the hand for this moment to test this on. :cry:
mbtest.PNG
(177.57 KiB) Downloaded 1299 times
Request:
01 01 0000 0004 3DC9
01 - Slave
01 - Function
0000 - Start register
0004 - Amount to read
3DC9 - CRC

Response
01 - SlaveID
01 - Function
01 - Bytes to follow (1, as 8 coils fit into one byte)
0F - Lower four are all on state 1.
118C - CRC

**************

Re: Modbus problems

Posted: Mon Feb 26, 2018 11:00 am
by Benj
Hi Rinie,

Can you confirm you are using a 19.6608MHz crystal to match the clock speed in the Project options? Also have you confirmed the micro is running at the right rate using the 1 second flasher test?

https://www.flowcode.co.uk/wikiv7/index. ... ED_flasher