Sn_IR(SENDOK) Interrupt
This is issued when SEND command is completed.
If this bit is reset, then either respective bit is not set in Sn_IMR, or there were no completed SEND command, or this bit was cleared by the user code.
If SEND_OK command is reset, I am making it set and transmitting again.
But sometimes I am getting Sn_SR command 0x1E or 0x2E, after that it goes to close state and again I am calling Initialization of W5500 chip.
I making as follows if I got wrong response
setSn_CR(sn,Sn_CR_SEND); // sn = Socket Number = 0, Sn_CR_SEND = 0x10
/* wait to process the command… */
while(getSn_CR(sn));
As of now I thought it is working properly, But is it require some delay between executing commands?
I think the best at this point for you is to read datasheet regarding the information on IR/IMR and Sn_IR/Sn_IMR flags and ask exact questions on things you do not understand. So far sounds you have some idea of how it may work, but it seems it does not…
You wrote: “But is it require some delay between executing commands?”
Yes, it does. After sending a command you should first wait for Sn_CR to be set to zero, then check Sn_SR for the status code(s) that may result from that command (e.g., for a “CLOSE” command you’d expect Sn_SR to change to SOCK_CLOSED). See page 47 of the datasheet, which says (in part):
“Sn_CR (Socket n Command Register) [R/W] [0x0001] [0x00]
This is used to set the command for Socket n such as OPEN, CLOSE, CONNECT,
LISTEN, SEND, and RECEIVE. After W5500 accepts the command, the Sn_CR register is
automatically cleared to 0x00. Even though Sn_CR is cleared to 0x00, the command
is still being processed. To check whether the command is completed or not, please
check the Sn_IR or Sn_SR.”
In addition, I’ve found that when running with a Cortex-M4 MCU at 120 MHz I need to insert delays in loops in which I’m polling the status register. Failing to do so seems to be especially harmful when sending a CONNECT or DISCON command, both of which require a handshake with a network peer. I suspect that polling too frequently interferes with the W5500’s ability to monitor the network.