WIZnet Developer Forum

ask about W5500 receive buffer write pointer

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.

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*/
}

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

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