Reading Sn_IR - gives 0xFF ??


I am setting to receive interrupts everytime a new frame is received on Socket 0 - MACRAW mode. When such interrupt happens, reading Sn_IR gives 0x04 .

In the main loop I do this

  1. Read from Socket 0 RX Buffer
  2. Write Sn_RX_RD with new read address
  3. Write RECV (0x40) to Sn_CR
  4. Read Sn_CR until it becomes 0x00
  5. Write 0xFF to Sn_IR to clear interrupts.

Immediately after that, I get interrupt with Sn_IR read value 0x40 . After that, further frame received interrupt has Sn_IR read value of 0x04 . Occasionally I get an interrupt where Sn_IR read 0xFF - after which the socket stops receiving further frames until I reopen the socket.

How do I prevent getting into this situation where Sn_IR read value of 0xFF ?

i found out the reason for the above behavior. This is due to oversight on my part.

When Interrupt handler, does a SPI read, while a SPI write is in progress in the main loop, it corrupts the main loop SPI write. This results in undefined behavior and crashes W5500.

To solve the problem, I disabled any interrupts while SPI read/write operation is in progress.