Author Topic: Possible issue with multiple Modbus Masters  (Read 4938 times)

Offline mhoneywill

  • Full Member
  • ***
  • Posts: 172
    • View Profile
Possible issue with multiple Modbus Masters
« on: December 01, 2011, 04:00:19 PM »
Hi Mark,

We are using the Modbus module V1.19 and have a situation where we have two independent Modbus masters communicating out via different Modbus ports.

If MasterA sends a request via Port1 (Uart0), then MasterB sends a request via Port2 (Uart1). The first reply received always goes to MasterA irrelevant of which Port it is received from. It seems like the Modbus engine can't cope with multiple masters transmitting at the same time, especially if replies are delayed.

Does the above make sense to you?

Cheers

Martin 

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2955
    • View Profile
    • uTasker
Re: Possible issue with multiple Modbus Masters
« Reply #1 on: December 01, 2011, 04:27:51 PM »
Hi Martin

Are these 'pure' MODBUS masters or are they performing routing functions?

When two masters are operating on two UART ports they should be completely independent. Each works with its own serial port handle and so all responses from a MODBUS slave will arrive at the port handle associated with the same MODBUS master.

The operation is however slightly different depending on whether the interface is in ASCII or RTU mode.

In ASCII mode the handle is used directly and whenever the MODBUS task is woken due to any reception on any UART the following takes place (only 2 ports shown)
    fnHandleASCIIInputs(0, ucModbusSerialInputBuffer[0]);
    fnHandleASCIIInputs(1, ucModbusSerialInputBuffer[1]);


Here all UART ports are checked to see whether they have data.

In RTU mode the task is worken by an interrupt message infoming of the UART channel that was just received on (due to RTU timing). The MODBUS port number (each port is assiciated with its own individual UART handle) is then handled specifically:

    unsigned char ucMODBUSport = (EVENT_VALID_FRAME_RECEIVED - ucInputMessage[MSG_INTERRUPT_EVENT]);

If you find that the first received answer is triggering always the first port you would probably see that the port number here is incorrect (always the first port).
This is triggered by the 3.5 character spacing timer firing: static void fnTimerT3_5_fired(unsigned char ucMODBUSport)
...
    fnInterruptMessage(OWN_TASK, (unsigned char)(EVENT_VALID_FRAME_RECEIVED - ucMODBUSport));


This would suggest that the root of such a problem could be in the timer. There is a HW timer allocated to each port (when the chip doesn't support such automatic operation on the UART).

At the moment I don't see how or where these timers (if you are in RTU mode) could interfere with each other. If you could home in a little on the source of the problem (handle, timer, mode etc.) I could then look in more detail to see whether I can explain something. If you could check in both RTU and ASCII mode to see whether one is OK but the other fails it would also be informative.

Regards

Mark



Offline mhoneywill

  • Full Member
  • ***
  • Posts: 172
    • View Profile
Re: Possible issue with multiple Modbus Masters
« Reply #2 on: December 01, 2011, 05:03:57 PM »
Hi Mark,

We are indeed using RTU and I will investigate the issue in more detail to find more information. Thanks as always for the quick response

Cheers

Martin