---
title: "W5500 TX Write Pointer calculation"
url: "https://maker.wiznet.io/forum/12406"
markdown_url: "https://maker.wiznet.io/forum/12406/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "flonas"
created: "2017-08-01T13:37:33+09:00"
last_activity: "2017-08-04T07:26:29+09:00"
language: "en"
views: 1040
replies: 1
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# W5500 TX Write Pointer calculation

## Question

Asked by flonas on 2017-08-01 in Ethernet Chips.

Hello,

I have a W5500 configured as a server and the PC is the client. I am having some problems with sending data over tcp and I want to make sure that I compute the Write Pointer properly. Since the Datasheet for the W5500 isn’t so explicit, I took the W5200 Datasheet and tried to set the Write Poiner. The code is the following:

```
// Socket 0 is used
uint32_t ptr      = getSn_TX_WR(socket_number);
uint32_t dst_mask = ptr & get_TxMASK(socket_number);     // get_TxMASK(0) returns 0x1FFF
uint32_t dst_ptr  = get_TxBASE(socket_number) + dst_mask;// get_TxBASE(0) returns 0x8000
```

Is this the right way to compute the destination pointer(*dst_ptr*) or am I doing something wrong ?

Thank you !

## Replies

### Reply 1 by lawrence, 2017-08-02

hello, flonas

W5500 has different memory structure from W5200.

please refer the ioLibrary for W5xxx.

![](https://github.githubassets.com/favicons/favicon.svg) [GitHub](https://github.com/Wiznet/ioLibrary_Driver)

![](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/0/0a32c0d1e6618fecaf7a1ea9c2fba2bb9ebe897e.png)

### [GitHub - Wiznet/ioLibrary_Driver: ioLibrary_Driver can be used for the...](https://github.com/Wiznet/ioLibrary_Driver)

ioLibrary_Driver can be used for the application design of WIZnet TCP/IP chips as W5500, W5300, W5200, W5100 W5100S. - GitHub - Wiznet/ioLibrary_Driver: ioLibrary_Driver can be used for the applica...

You can check the W5500 memory access.

> ```
// refer W5500  memory map
#define WIZCHIP_TXBUF_BLOCK(n) (2+4*n)
 
// calculate physical memory address and 'addrsel' is for spi interface address and control phase
uint16_t ptr = (WIZCHIP_READ(Sn_TX_WR(n)) >> 8) + WIZCHIP_READ(Sn_TX_WR(n)+1) ;
uint32_t addrsel = ((uint32_t)ptr << 8) + (WIZCHIP_TXBUF_BLOCK(n) << 3);

// copy data to tx memory
WIZCHIP_WRITE_BUF(addrsel, data, len);

// increase sn_tx_wr
ptr += len;
WIZCHIP_WRITE(Sn_TX_WR(n), ptr);

// send command
WIZCHIP_WRITE(Sn_CR(n), Sn_CR_SEND);

// send command done
while(WIZCHIP_READ(Sn_CR(n)));
```

Thank you

lawrence

---

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