PIC to PIC serial communication

Discussion in 'Embedded Systems and Microcontrollers' started by MaxD, May 12, 2012.

  1. MaxD

    Thread Starter New Member

    May 5, 2012
    11
    0
    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.
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,365
    I am not sure what you mean by "coil".
    Perhaps you are referring to the input pins of PORTA and PORTB of the slave.
     
  3. MaxD

    Thread Starter New Member

    May 5, 2012
    11
    0
    Ok, how can i define PORTB(0to7) for DATA to read?
     
  4. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,365
    What language/platform are you using?

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

    Thread Starter New Member

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

    Moderator

    Oct 2, 2009
    12,449
    3,365
    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?
     
  7. MaxD

    Thread Starter New Member

    May 5, 2012
    11
    0
    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?
     
  8. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,365
    Which MODBUS command are you implementing?

    What programming language and IDE platform are you using?
     
  9. MaxD

    Thread Starter New Member

    May 5, 2012
    11
    0
    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.
     
  10. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,365
    Just use PORTA to get the value of PORTA.
     
Loading...