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 ?
PIC AS MODBUS SLAVE WITH FLOWCODE7
Moderator: Benj
-
- Posts: 115
- Joined: Wed Aug 03, 2016 10:45 pm
- Has thanked: 24 times
- Been thanked: 11 times
PIC AS MODBUS SLAVE WITH FLOWCODE7
Last edited by EtsDriver on Tue Nov 29, 2016 8:31 pm, edited 1 time in total.
Reason: Edited uppercase letters for better read-ability. Its not generally good idea to "yell" eg. use UPPERCASE for all your writings. Welcome to forums!
Reason: Edited uppercase letters for better read-ability. Its not generally good idea to "yell" eg. use UPPERCASE for all your writings. Welcome to forums!
- 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: PIC AS MODBUS SLAVE WITH FLOWCODE7
Hello and welcome,
There are some examples here that should help you get started.
http://www.matrixtsl.com/wikiv7/index.p ... 13dcb57a13
Let us know how you're getting on.
There are some examples here that should help you get started.
http://www.matrixtsl.com/wikiv7/index.p ... 13dcb57a13
Let us know how you're getting 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
-
- Posts: 115
- Joined: Wed Aug 03, 2016 10:45 pm
- Has thanked: 24 times
- Been thanked: 11 times
Re: PIC AS MODBUS SLAVE WITH FLOWCODE7
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.
FOR HELP I SEND YOU THE FLOWCODE7 PIC CODE, AND A SIMPLIFIED SCHEMATIC FOR HARDWARE BOARD.
MANY THANKS.
- Attachments
-
- ModBus_Slave_DEMO1.zip
- THIS IS THE CODE FOR TEST A MODBUS COMMAND
- (2.43 KiB) Downloaded 432 times
-
- MBLCD01.zip
- THIS IS PART OF SLAVE-HARDWARE SCHEMATIC (EAGLE 6.3)
- (29.35 KiB) Downloaded 399 times
-
- Valued Contributor
- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
Re: PIC AS MODBUS SLAVE WITH FLOWCODE7
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).
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
- 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: PIC AS MODBUS SLAVE WITH FLOWCODE7
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.
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.
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
-
- Valued Contributor
- Posts: 1189
- Joined: Wed Dec 31, 2008 3:37 pm
- Has thanked: 460 times
- Been thanked: 523 times
Re: PIC AS MODBUS SLAVE WITH FLOWCODE7
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
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
Success always occurs in private and failure in full view.
- 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: PIC AS MODBUS SLAVE WITH FLOWCODE7
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.
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.
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: 115
- Joined: Wed Aug 03, 2016 10:45 pm
- Has thanked: 24 times
- Been thanked: 11 times
Re: PIC AS MODBUS SLAVE WITH FLOWCODE7
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.
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.
- Attachments
-
- ModBus_Slave_DEMO2.fcfx
- (10.71 KiB) Downloaded 408 times