Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - kiryat8

Pages: [1]
1
NXPTM LPC2XXX and LPC17XX / Modbus User task callback
« on: September 10, 2014, 07:06:44 AM »
When implementing a Modbus RTU slave...
I have all NULL pointers passed to the fnInitialiseMODBUS_port() function so I get an user callback.
static int fnMODBUSSlaveuserFunction(int iType, MODBUS_RX_FUNCTION *modbus_rx_function)
Using the code below I determine which Modbus command was received and handle accordingly.
  switch(iType){
    case USER_RECEIVING_MODBUS_UNDEFINED_FUNCTION:
       switch (modbus_rx_function->ucFunctionCode){
          case MODBUS_WRITE_SINGLE_REGISTER://         0x06
             ...
             fnMODBUS_transmit(modbus_rx_function,modbus_HostBuf,8);
             return 0;
           case MODBUS_WRITE_MULTIPLE_REGISTERS://      0x10
       } // switch Modbus message type
  } // switch

1) The problem I have is that I get two calls to the function.
  The first time when receiving the incoming message and the second time after my reply was sent.
  In the read request message I checked the MODBUS_RX_FUNCTION fields to detect the reply,
  BUT in the MODBUS_WRITE_SINGLE_REGISTER the reply is exactly the same as the incoming message.
  How can I differentiate between the reply and the incoming callbacks?

2) I receive the MODBUS_WRITE_MULTIPLE_REGISTERS message as 0x90 instead of 0x10.
I can not find out why?

Thanks
David Kaplan




Pages: [1]