---
title: "Reading Sn_IR - gives 0xFF ??"
url: "https://maker.wiznet.io/forum/14457"
markdown_url: "https://maker.wiznet.io/forum/14457/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "ngaihua"
created: "2022-01-28T03:40:25+09:00"
last_activity: "2022-02-01T06:42:14+09:00"
language: "en"
views: 308
replies: 1
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# Reading Sn_IR - gives 0xFF ??

## Question

Asked by ngaihua on 2022-01-28 in Ethernet Chips.

Hello,

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 ?

## Replies

### Reply 1 by ngaihua, 2022-02-01

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.

---

Source: https://maker.wiznet.io/forum/14457
