---
title: "ask about W5500 receive buffer write pointer"
url: "https://maker.wiznet.io/forum/13576"
markdown_url: "https://maker.wiznet.io/forum/13576/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "kejuqeju"
created: "2019-11-20T04:09:58+09:00"
last_activity: "2019-11-22T01:07:42+09:00"
language: "en"
views: 710
replies: 2
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# ask about W5500 receive buffer write pointer

## Question

Asked by kejuqeju on 2019-11-20 in Ethernet Chips.

Hello there…
i read the W5500 datasheet. If W5500 receives data on socket 0, then S0_RX_WR pointer register will be added with data size. then I must get the data from socket 0 receive buffer, as many as S0_RX_RSR. and then i must update the S0_RX_RD pointer register to the increased value as many as the reading size, and send RECV command to notify W5500 that i have collect the new data. I use 2KB buffer for socket 0 here.
My question is, eventually the S0_RX_WR will reach 2048 or more, but the buffer size is only 2048 bytes. The pointer will exceed the buffer size.
Is there any way to reset the S0_RX_WR to 0 everytime i have collect the data? I don’t want to CLOSE / DISCONNECT socket every time a new data comes.

## Replies

### Reply 1 by becky, 2019-11-21

It is not a problem for Sn_RX_WR to exceed 2048. Socket is also not CLOSE. You can write code and read data in the flow shown below.

```
{
/* get Received Size */
 get_size = Sn_RX_RSR;
 /* calculate SOCKET n RX Buffer Size & Offset Address */
 gSn_RX_MAX = Sn_RXBUF_SIZE * 1024;
 get_offset = Sn_RX_RD & gSn_RX_MASK;

60 / 109 W5100S Datasheet Version1.0.0
 /* calculate Read Offset Address */
 get_start_address = gSn_RX_BASE + get_offset;
 /* if overflow the upper boundary of SOCKET n RX Buffer */
 If( (get_offset + get_size) > gSn_RX_MAX )
 {
 /* copy upper_size bytes of get_start_address to destination_address
 - destination_address is user data memory address */
 upper_size = gSn_RX_MAX – get_offset;
 memcpy(get_start_address, destination_address, upper_size);
 destination_address += upper_size;
 /* copy the remained size bytes of gSn_RX_BASE to destination_address */
 remained_size = get_size – upper_size;
 memcpy(gSn_RX_BASE, destination_address, remained_size);
 }
 else
 {
 /* copy get_size of get_start_address to destination_address */
 memcpy(get_start_address, destination_address, get_size);
 }
 /* increase Sn_RX_RD as get_size */
 Sn_RX_RD += get_size;
 /* set RECV Command */
 Sn_CR[RECV] = ‘1’;
 while(Sn_CR != 0x00); /* wait until RECV Command is cleared*/
}
```

### Reply 2 by kejuqeju, 2019-11-21

Ok, i have successfully applied you algorithm… thank you.

---

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