• AVR Freaks

Hot!PIC18F4520 with MODBUS Communication

Author
john_ive
Super Member
  • Total Posts : 227
  • Reward points : 0
  • Joined: 2017/05/22 22:22:08
  • Location: 0
  • Status: offline
2020/06/30 03:13:53 (permalink)
0

PIC18F4520 with MODBUS Communication

Hai,
This is the first project going to work with MODBUS Communication.
In this project I'm using PIC18F4520 as master device to set and read values from Slave.Slave will use MODBUS communication.
 
So please provide some guide lines to communicate between each other.
My doubts are.
1.Shall we connect TX and RX pin directly to DATA + and DATA -.?
2.If I use an RS232 to RS485 Convertor means,Shall I use MAX232 module between PIC Controller and convertor to communicate.?
 
#1

8 Replies Related Threads

    ric
    Super Member
    • Total Posts : 28009
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC18F4520 with MODBUS Communication 2020/06/30 03:23:33 (permalink)
    +1 (1)
    john_ive
    1.Shall we connect TX and RX pin directly to DATA + and DATA -.?

    No. I suggest you start reading what MODBUS is, and what DATA+ and DATA- are.
     

    2.If I use an RS232 to RS485 Convertor means,Shall I use MAX232 module between PIC Controller and convertor to communicate.?

    That would be a silly way to do it.
    Use a TTL to RS485 converter. It's just one chip.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    crosland
    Super Member
    • Total Posts : 2017
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: PIC18F4520 with MODBUS Communication 2020/06/30 05:04:11 (permalink)
    +1 (1)
    john_ive
    1.Shall we connect TX and RX pin directly to DATA + and DATA -.?

     
    Why do you think you would want to do that?
    #3
    john_ive
    Super Member
    • Total Posts : 227
    • Reward points : 0
    • Joined: 2017/05/22 22:22:08
    • Location: 0
    • Status: offline
    Re: PIC18F4520 with MODBUS Communication 2020/07/14 03:04:25 (permalink)
    0
    In PIC18F4520 Controller in UART, master will send data to slave,there is no data is transferred from slave to master.So I used only TX to communicate with slave and RX pin for relay operation.
    While executing this line
    RCSTAbits.SPEN = 1; /* enable serial port pins */
    ,I can't use RX pin for general purpose.If SPEN is disabled means communication not working.
     
    How to solve this issue.?
    TX pin have to use for communication and RX pin have to use for general purpose
    #4
    ric
    Super Member
    • Total Posts : 28009
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC18F4520 with MODBUS Communication 2020/07/14 03:08:16 (permalink)
    +1 (1)
    john_ive
    ...
    While executing this line
    RCSTAbits.SPEN = 1; /* enable serial port pins */
    ,I can't use RX pin for general purpose.

    Why not?
    Have you tried?
    "General purpose" what? You don't reveal if you mean input or output.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    hasanyildiz
    Starting Member
    • Total Posts : 59
    • Reward points : 0
    • Joined: 2015/09/04 03:33:31
    • Location: 0
    • Status: offline
    Re: PIC18F4520 with MODBUS Communication 2020/07/14 03:48:08 (permalink)
    0
    Hi John,
    1.Shall we connect TX and RX pin directly to DATA + and DATA -.?
    Never do that. Use SN75176 like TTL to RS485 convertor chip and connect your RX pin to R and TX pin to D.
    You also need to use extra io to control Recieve or Transmit state of this chip.  
     
    2.If I use an RS232 to RS485 Convertor means,Shall I use MAX232 module between PIC Controller and convertor to communicate.?
    No need do this.
    #6
    john_ive
    Super Member
    • Total Posts : 227
    • Reward points : 0
    • Joined: 2017/05/22 22:22:08
    • Location: 0
    • Status: offline
    Re: PIC18F4520 with MODBUS Communication 2020/07/14 04:30:53 (permalink)
    0
    ric
    john_ive
    ...
    While executing this line
    RCSTAbits.SPEN = 1; /* enable serial port pins */
    ,I can't use RX pin for general purpose.

    Why not?
    Have you tried?
    "General purpose" what? You don't reveal if you mean input or output.
     


    Yes tried it.
    After disable,there is no communication between both master and slave.
    RX pin is used for input operation
    #7
    ric
    Super Member
    • Total Posts : 28009
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC18F4520 with MODBUS Communication 2020/07/14 04:39:59 (permalink)
    +1 (1)
    By "tried", I meant did you try using it for general purpose I/O, not did you try turning SPEN off.
    You can still use the pin as a general purpose input while SPEN is set. Just try it.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #8
    crosland
    Super Member
    • Total Posts : 2017
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: PIC18F4520 with MODBUS Communication 2020/07/15 12:16:16 (permalink)
    -1 (1)
    john_ive
    there is no data is transferred from slave to master.



    Are you sure that the MODBUS protocol does not require two-way communication, even if the data flow is unidirectional?
     
    I think you might find the master is expecting a response from the slave.
    #9
    Jump to:
    © 2020 APG vNext Commercial Version 4.5