|
|
View previous topic :: View next topic |
Author |
Message |
SILVESTROS
Joined: 30 Dec 2016 Posts: 2
|
MODBUS SLAVE WITH PIC |
Posted: Fri Dec 30, 2016 1:47 pm |
|
|
Hello to all.
I try to send some characters with Modbus protocol (bus type RS-485), to an 4X20 LCD, that I connected with a PIC16F887. The pic works as slave, while I use as master a master emulator (ComTestPro) to send data to make some tests first, and later I'll use a PLC. Communication with pic is ok, Modbus commands 01,02,03 work fine, but I've a problem with write data to pic registers and send that to LCD.
I'm new in pic programming, so I don't know how to address pic registers, what kind of variable I must use, and how to send that var. to LCD to display a character. The LCD accepts var. types as PrintString, PrintAscii, PrintNumber. LCD works fine when I use PrintString " ", but when I use the var. that I used at MB com. 06 (write single register), LCD shows 0 or 0x00.
Thanks in advance for any help or advice. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Fri Dec 30, 2016 2:11 pm |
|
|
Standard Modbus registers are int16.
Generate a string.
Code: |
char temp_str[17]; //assuming a 16 char LCD
sprintf(temp_str,"%lu", register_variable);
|
Obviously the 'register_variable' will need to be the same one you use in the Modbus code.
Once the string is generated, this can be sent with your printstring function.
If you are a slave, you need to _read_ the register. Master writes, slave reads. |
|
|
SILVESTROS
Joined: 30 Dec 2016 Posts: 2
|
|
Posted: Sun Jan 01, 2017 8:30 am |
|
|
Thanks Ttelmah for info.
About modbus slave code, because pic is the slave, do you mean that first I must use Write Single Register function (06), after Read Single Register (03) and then send the string to LCD , or the opposite? Is it possible to send me a sample code for generating the string to PrintString command for LCD?
Many thanks in advance, and happy New Year. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Sun Jan 01, 2017 9:12 am |
|
|
No, you said you wanted to 'write some data to PIC registers'. If the Modbus master is sending data to the PIC, then the PIC has to read this. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|