PIC to PIC serial communication

Thread Starter

MaxD

Joined May 5, 2012
11
I'm doing a project that serial communication between PIC. I use a PIC 16f877a as master device and another PIC 16f877a as slave device. Also, I'm using MODBUS protocol in the communication. So, in the slave program code, for example, master want to read coil from slave then the slave need to response the status to the master.

My question is, in slave device, how to assign the coils of the ports to read whether it is ON/OFF(1/0)? If master only want to read PORTA & PORTB from the slave device.
 

MrChips

Joined Oct 2, 2009
30,810
I am not sure what you mean by "coil".
Perhaps you are referring to the input pins of PORTA and PORTB of the slave.
 

MrChips

Joined Oct 2, 2009
30,810
What language/platform are you using?

If you are using MODBUS I assume you are using the serial interface. Is that correct?
 

Thread Starter

MaxD

Joined May 5, 2012
11
MrChips, yes, you are right. I'm just don't know how to program the slave to respond its status. >.<
 

MrChips

Joined Oct 2, 2009
30,810
You have to read up on the MODBUS protocol.

The slave will receive a command from the master.
The slave will respond with the information the master is requesting.

Which command(s) do you wish to implement?
 

Thread Starter

MaxD

Joined May 5, 2012
11
I have done slave receive command from master, but for slave respond info to master I get confused here.

For example,
master want to read PORT B status (I set PORT B as output) on the slave device. So master will send command to slave, now slave needs to respond its status and then send it back to the master.
So how do I get the data from the port?
 

Thread Starter

MaxD

Joined May 5, 2012
11
I'm using MPLAB IDE, HI-TECH C Compiler for this project. The programming language I used is C language. I'm using RTU mode for transmission.
 
Top