Connect with us

Modbus master and slave on single micro controller!!!!

Discussion in 'Microcontrollers, Programming and IoT' started by paddy, Feb 1, 2013.

Scroll to continue with content
  1. paddy

    paddy

    81
    0
    Sep 11, 2012
    Hello,

    Greetings of the day!!!!!!

    I have to implement modbus master and modbus slave code on a single micro controller.

    I am using PIC18F46K22 micro controller which is having 2 USARTs.

    First of all is it possible to implement both master and slave on a single micro controller.

    And if yes how to synchronize them?

    Thanks,
    paddy
     
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    11,513
    2,651
    Nov 17, 2011
    1) Implementing master and slave should be no problem. Use 1 UART for the master, the second UART for slave. You will need 2 physical transceivers.

    As for synchronization: What exactly do you mean by that? They should be able to work independently.
     
    Last edited: Feb 1, 2013
  3. paddy

    paddy

    81
    0
    Sep 11, 2012
    Thanks for your kind reply sir!!!

    Say i have read the data from one slave device and stored it somewhere in memory and then that data will be sent to another master device from slave code.

    Now if query comes from master device and at the same time if controller is executing master code, in that case i might get communication error or timeout error.

    Please correct me if I am wrong.

    And if it is true, how can i avoid it?

    Thanks,
    paddy
     
    Last edited: Feb 1, 2013
  4. gorgon

    gorgon

    603
    24
    Jun 6, 2011
    The easiest way to get past this problem is to use interrupt routines for the receive and transmit to and from the UARTS. You process the records in the background, where you have more time. This is fairly easy as long as you have a full duplex communication. If you need to use half duplex you'll need to make some extra hardware control in the interrupt routines, at least for the master channel.

    To process two independant channels you'll need some form of round robin main loop, that is going continuously around checking for things to do on each channel in sequence. It is normal to control the processes with flags or semaphores tha signal need for activity, to make it all look as real time execution.
     
  5. paddy

    paddy

    81
    0
    Sep 11, 2012
    Thanks for your reply sir!!!
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-