Maker Pro
Maker Pro

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

paddy

Sep 11, 2012
81
Joined
Sep 11, 2012
Messages
81
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
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
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:

paddy

Sep 11, 2012
81
Joined
Sep 11, 2012
Messages
81
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:

gorgon

Jun 6, 2011
603
Joined
Jun 6, 2011
Messages
603
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.
 
Top