WIZnet Developer Forum

Issue with W5500 hardware interrupt

I need to catch incoming TCP packets by interruption.

I have implemeneted following :

  1. In the loop, I invoke the register check procedure Sn_IR (Sn_IMR = 0x1F);
  2. If the RECV = 1 bit in the Sn_IR register, at the first I call a procedure for reading the packet and after the procedure for sending the response packet;
  3. After reading a packet and sending the response, the Sn_IR register automatically resets to 0x00;
    That’s how it works.

Now, If I turn on the hardware interrupt, I have did following:

  1. Chip initialization procedure sets the register SIMR = 0xFF (although only one socket is used);
  2. Interrupt procedure check the RECV bit in the Sn_IR register. If bit RECV = 1 then set the flag FL_INT_RECV and leave the interrupt;
  3. In the loop:
    A procedure of flag FL_INT_RECV verification invokes. If the flag is set, then a procedure calls for reading the packet, sending the response packet and reset flag
    by resetting the interrupt bits:
  • setSIR (0x00);
  • setSn_IR (SOCK_TCP, 0x1F);

In doing so, I receive one packet and can send one response only. The INT line stays low (SIR != 0x00, Sn_IR != 0x00).
What I am doing wrong? Please, I will be thankful for any suggestions.

I recommend you set Sn_IMR to 0x04. If so, the interrupt occurs only when it is recv, so there is no need to check if it is a recv interrupt when the interrupt occurs.

setSIR (0x00) is meaningless. SIR is automatically cleared according to Sn_IR. If you did setSn_IR (SOCK_TCP, 0x1F), the interrupt is cleared and the INT line should go high. If setSn_IMR (0xff) is set and you set setSn_IR (SOCK_TCP, 0x1F) in recv only, interrupts may occur in other bits and thus may not be cleared. This can be solved by setting 0x04 in sn_imr.

Thanks for your reply. Everything works fine now!
Do I understand correctly that I only need to reset the bit in the Sn_IR register that raised an interrupt?

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.