Page 1 of 1
PIC AS MODBUS SLAVE WITH FLOWCODE7
Posted: Mon Nov 28, 2016 10:28 pm
by SILVESTROS9
I work for a project, where i use a pic (pic 16f887) as modbus slave . Because i don't know c language ,but only pic-basic , i 'll try to use flowcode7 that is excellent for that programming level . The basic goals are to send some messages from a plc device to a common lcd 4x20 char., and set some pic outputs on or off with modbus commands. For that , i connect a plc device with rs-485 to pic that drive the lcd and some outputs. Using
The flowcode7 component modbus slave, to send modbus commands to pic's uart, and lcd 4x20 component to send the messages to lcd , that part of code are relatively easy. My problem is how to make the modbus map in pic memory according to modbus protocol and handle the data from pic's uart to registers of pic's memory , and from pic modbus map to lcd and outputs. Any idea on how to use flowcode for that , or sample code , or anything to help me realize that project ?
Re: PIC AS MODBUS SLAVE WITH FLOWCODE7
Posted: Tue Nov 29, 2016 10:46 am
by Benj
Hello and welcome,
There are some examples here that should help you get started.
http://www.flowcode.co.uk/wikiv7/index.p ... 13dcb57a13
Let us know how you're getting on.
Re: PIC AS MODBUS SLAVE WITH FLOWCODE7
Posted: Thu Dec 15, 2016 11:29 pm
by SILVESTROS9
THANKS FOR INFO. I STARTED WITH MAKING THE HARDWARE. A DEMONSTRATION BOARD WITH A PIC 16F887 , A SN75176B BUS TRANSCEIVER AND A LCD 4X20. THE PIC IS THE MODBUS SLAVE, AND AS MODBUS MASTER I'LL USE A MODBUS PLC DEVICE AT THE END. FOR TESTS I USE A MODBUS MASTER EMULATOR TO SEND MODBUS COMMANDS TO PIC FROM A LAPTOP WITH USB-RS485 CONVERTER. I USE FLOWCODE7 TO MAKE A SIMPLE TEST CODE FOR A MODBUS COMMAND (SET COIL STATE),TO VERIFY SEND-RECEIVE DATA IS OK. BUT WHEN I SEND DATA FROM MASTER EMULATOR TO PIC I HAVE THE MESSAGE "NO RESPONSE". I CHECK THE HARDWARE CIRCUIT, I DON'T FIND SOMETHING WRONG. THE SAME FOR THE PIC CODE. FOR THAT I DID'T MADE THE BASIC PART OF PIC CODE THAT IS TO SEND A MESSAGE TO LCD WITH MODBUS MASTER.FIRST I WOULD LIKE TO SEND SIMPLE MODBUS COMMANDS TO TEST THE MODBUS COMMUNICATION BETWEEN MASTER AND SLAVE. IS THERE ANY IDEA FOR THE REASON FOR THAT ERROR? WHERE IS THE PROBLEM , AT HARDWARE OR AT PIC CODE? IT SEEMS THAT THE PIC RECEIVES THE DATA BUT THERE IS NO RESPONSE ACCORDING MODBUS PROTOCOL.
FOR HELP I SEND YOU THE FLOWCODE7 PIC CODE, AND A SIMPLIFIED SCHEMATIC FOR HARDWARE BOARD.
MANY THANKS.
Re: PIC AS MODBUS SLAVE WITH FLOWCODE7
Posted: Mon Dec 19, 2016 12:19 am
by kersing
Please do not write entire messages in upper case. It is hard to read (to the point where I don't even bother) and is interpreted as shouting at people. Use lower case for you text and only upper case where required (start of sentence etc).
Re: PIC AS MODBUS SLAVE WITH FLOWCODE7
Posted: Mon Dec 19, 2016 11:42 am
by Benj
Hello,
I can't view the contents of the .sch file. Is it possible to send this as a screen shot Jpg file.
I've spotted a few things wrong with the program but nothing that should have stopped the slave from replying.
Here is a slightly modified version which will output the first 8 coil states to LEDs if a valid command from a master is received.
Re: PIC AS MODBUS SLAVE WITH FLOWCODE7
Posted: Mon Dec 19, 2016 1:42 pm
by Steve001
here you go ben
SILVESTROS9
rather than uploading a .sch file if you print as pdf more people will be able to help you as not every one has access to eagle
steve
Re: PIC AS MODBUS SLAVE WITH FLOWCODE7
Posted: Mon Dec 19, 2016 3:48 pm
by Benj
Aha thanks Steve,
That helps. Looks like you're using RS485 communications and your current program is setup for RS232 direct connections.
Looks like you need to switch the Modbus component to the RS485 mode and then provide the DDR property as pin A1. Hopefully that's all you need to do.
Re: PIC AS MODBUS SLAVE WITH FLOWCODE7
Posted: Mon Dec 19, 2016 8:13 pm
by SILVESTROS9
Hello to all.
To Kersing ..... sorry to you and to all users, you're right. It's my mistake, no excuses.
To Steve001 ..... your idea is better, thanks for converting the schematic to .pdf .
To Benj .......many thanks for your help and support.
About my project, that is for now experimental, I made some modifications to hardware and code, and it seems to works fine for some Modbus commands.Some Modbus master emulator give me crc error , another give me no errors. With the code that I upload below, I use Modbus command 5 (Write Single Coil - SetCoilState for FLOWCODE7 Modbus slave component) , to send a byte to PORTB of pic .The byte at pic PORTB is correct, the bus type is RS485 .That was for communication test. My main target is to send a strings of characters to LCD. I noticed that Modbus slave component does not support a Modbus commands as 15 (Write Multiple Coils), and 16 (Write Multiple Registers), unless I make a mistake. I'll try to playing with read/write register macros of FLOWCODE7 Modbus slave component . I must write a string to pic registers and send that data to LCD. It helps me any idea or code for that.
Thanks.