CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

MODBUS SLAVE WITH PIC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
SILVESTROS



Joined: 30 Dec 2016
Posts: 2

View user's profile Send private message

MODBUS SLAVE WITH PIC
PostPosted: Fri Dec 30, 2016 1:47 pm     Reply with quote

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: 19513

View user's profile Send private message

PostPosted: Fri Dec 30, 2016 2:11 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jan 01, 2017 8:30 am     Reply with quote

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: 19513

View user's profile Send private message

PostPosted: Sun Jan 01, 2017 9:12 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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