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