This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RM46L852: Modbus Over TCP/IP, control hand in TCP Rx interrupt

Part Number: RM46L852

Hello,

We have implemented Modbus protocol over TCP using lwip Stack without using any RTOS. Our control send the Modbus Queries 0x03 (Read Holding Register) and 0x10 (Write Multiple register)on every 1 seconds.

For Testing, We are using PLC Slave modbus simulator from Modbustools.com with our control.

In Halogen, under EMAC tab we configured "No of receive packet buffer" as 10. We also tested by setting buffer to 15 and 30 and in both cases, control stuck in receive interrupt in less than 20sec time.

We observed that Control works properly for Few seconds (repeatedly observed control works around  22 seconds ) then control hangs in Rx_Interrupt handler  loop forever, Can anyone help on to resolve the issue?

 

Query and response log is attached below. Last query and response is highlighted in below log

  • Hi Pramod,

    The EMAC module has 8K bytes internal memory for descriptors. The EMAC module can send and receive up to a combined 512 packets before it needs to be serviced by application.

    How long does the RX ISR take to process your data? and how fast does your tool TX data to EMAC? The tool might transmit the packets too fast.
  • QJ,

    Thanks For your Reply.

    Earlier we used to fill our local buffer into Rx ISR as well as Process that data to Modbus Application code . We have moved that Process function in main loop and reduce the Emac Rx isr time.

    But still we observe the same result(after 22sec Control hang in hdkif_rx_inthandler() function). One more Observation, Once it stuck in Rx Isr loop  Control start increment  RXDMA and RXOver run Emac registers. please find below captured snap.

    We have checked and Tool response time we set 10msec. Also We have tested with Two different tool and we observe the same behaviour.

  • Hi Pramod,

    Please limit the throughput from the Modbus side.
  • Hello QJ,

    I have limited the Throughput from Modbus side. Now, Control Transmit the query after 200msec and Modbus Tool response time also increased from 10msec to 100msec.

    But still we observed the same result.  Control stuck in Rx ISR loop as mentioned in above thread.  

  • QJ,

    One more observation,
    When Control stops in hdkif_rx_inthandler function, "rxch->active_head" is became Zero and hence "curr_bd". We tried to put the condition by braking the loop(while(hdkif_swizzle_data(curr_bd->flags_pktlen) & EMAC_BUF_DESC_SOP)) when ever this condition occurs but Control will initiate some transition but again fails.

    We have other TCP application(like httpd server, FTP Client, SNTP client and XCP protocol etc) which works perfectly without having any problem. Only Modbus over TCP application fails after certain time.

    I request you , kindly go through the log attached with initiation thread. do you think we missed something there.
  • Hello QJ,

    can you please provide your input. 

    Regards,

    Pramod Gaikwad

  • Can anyone  LWIP expert comment on above Modbus over TCP issue? I am stuck ....

  • I have resolved this issue,

    It was my mistake in code in the Receive call back function that I was not freeing up the pubf pointer.

    after placing the following condition,

    static err_t ModbusTCPrecv(void *arg, struct tcp_pcb *Rcevtpcb, struct pbuf *ptrModbusResBuf, err_t errMDRcvTCP)
    {
         if(ptrModbusResBuf)
        {
            // Copy the received data from MOBUS TCP slave to local buffer

           pbuf_free(ptrModbusResBuf); /*added this condition to resolve the issue*/
        }
    }

    Thank you QJ for your kind support.