---
title: "Rx Buffer Always returns 0x00"
url: "https://maker.wiznet.io/forum/12643"
markdown_url: "https://maker.wiznet.io/forum/12643/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "nocturnal"
created: "2018-01-05T22:00:51+09:00"
last_activity: "2018-01-06T20:17:14+09:00"
language: "en"
views: 967
replies: 1
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# Rx Buffer Always returns 0x00

## Question

Asked by nocturnal on 2018-01-05 in Ethernet Chips.

Hello all,

I’m new to arm and wiznet chips. So far, I’ve written a quarter of my own W5500 library (not tidied, yet). I also ran the tcp server code which uses built-in library on Wiznet site. (I used to send and receive data via TCP protocol and it means my hw and chips are ok!)

Now… with my manual library;

- I can init W5500.

- I can configure and run it as TCP Server

- I can read and write internal registers

- I can see how many bytes received on Socket 0 correctly

- I can read and write rx buffer pointer correctly

But my problem is that I always read 0x00 from RX buffer on Socket 0.

Here is my part of code:

while(1){

if (W5500_REG_READ_BYTE(SOCKET0_REGISTER_BLOCK, Sn_SR) == SOCK_ESTABLISHED){

```
		received_data_size = W5500_GET_RECEIVED_DATA_SIZE(); //WORKS
		
		if((received_data_size) != 0){				
			rx_buff_data_pointer = W5500_GET_RECEIVED_DATA_POINTER();
				
			for(int i = 0; i<2048; i++)                                           
            test_receive_buffer[i] = W5500_REG_READ_BYTE(SOCKET0_RX_BUFFER, i);
			//ALWAYS RETURNS 0x00!
		
			local_rx_buff_data_pointer += received_data_size;
			  W5500_REG_WRITE_BYTE(SOCKET0_REGISTER_BLOCK, Sn_RX_RD_MSB, 0);
			  W5500_REG_WRITE_BYTE(SOCKET0_REGISTER_BLOCK, Sn_RX_RD_LSB, local_rx_buff_data_pointer); //WORKS
			
				W5500_REG_WRITE_BYTE(SOCKET0_REGISTER_BLOCK, Sn_CR, SOCKET_RECV); //WORKS
			test_receive_buffer5 = W5500_REG_READ_BYTE(SOCKET0_REGISTER_BLOCK, Sn_SR); //EXTRA FUNCTION TEST WORKS

			}

		}
```

}

I also tried to read all 2048 bytes of data and saw nothing except a few foreign characters in the middle.

Here is my read byte function:

// READ BYTE FUNCTION

uint8_t W5500_REG_READ_BYTE(uint8_t r_W5500_REG_BLOCK, uint16_t r_W5500_REG_ADD){

```
uint8_t r_DataPhase;
uint8_t r_control_phase		= (r_W5500_REG_BLOCK << 3) | (W5500_READ_FLAG << 2 ) | (W5500_OPERATION_MODE);
uint8_t r_reg_add_offset1 = (r_W5500_REG_ADD >> 8) & 0xFF; 
uint8_t r_reg_add_offset2 =  r_W5500_REG_ADD & 0xFF;

#if W5500_OPERATION_MODE ==  VARIABLE_DATA_LENGTH_MODE

HAL_GPIO_WritePin(SCSn_GPIO_Port, SCSn_Pin, GPIO_PIN_RESET);

if(((HAL_SPI_ERROR_STATE = HAL_SPI_Transmit(&W5500_SPI_PORT, &r_reg_add_offset1, sizeof(r_reg_add_offset1), W5500_SPI_TIMEOUT)) != HAL_SPI_ERROR_NONE)) goto W5500_REG_READ_BYTE_RET;
if(((HAL_SPI_ERROR_STATE = HAL_SPI_Transmit(&W5500_SPI_PORT, &r_reg_add_offset2, sizeof(r_reg_add_offset2), W5500_SPI_TIMEOUT)) != HAL_SPI_ERROR_NONE)) goto W5500_REG_READ_BYTE_RET;
if(((HAL_SPI_ERROR_STATE = HAL_SPI_Transmit(&W5500_SPI_PORT, &r_control_phase, sizeof(r_control_phase), W5500_SPI_TIMEOUT)) != HAL_SPI_ERROR_NONE)) goto W5500_REG_READ_BYTE_RET;
if(((HAL_SPI_ERROR_STATE = HAL_SPI_Receive(&W5500_SPI_PORT, &r_DataPhase, sizeof(uint8_t), W5500_SPI_TIMEOUT)) != HAL_SPI_ERROR_NONE)) goto W5500_REG_READ_BYTE_RET;

HAL_GPIO_WritePin(SCSn_GPIO_Port, SCSn_Pin, GPIO_PIN_SET);

#elif W5500_OPERATION_MODE ==  FIXED_1BYTE_DATA_LENGTH_MODE

if(((HAL_SPI_ERROR_STATE = HAL_SPI_Transmit(&W5500_SPI_PORT, &r_reg_add_offset1, sizeof(r_reg_add_offset1), W5500_SPI_TIMEOUT)) != HAL_SPI_ERROR_NONE)) goto W5500_REG_READ_BYTE_RET;
if(((HAL_SPI_ERROR_STATE = HAL_SPI_Transmit(&W5500_SPI_PORT, &r_reg_add_offset2, sizeof(r_reg_add_offset2), W5500_SPI_TIMEOUT)) != HAL_SPI_ERROR_NONE)) goto W5500_REG_READ_BYTE_RET;
if(((HAL_SPI_ERROR_STATE = HAL_SPI_Transmit(&W5500_SPI_PORT, &r_control_phase, sizeof(r_control_phase), W5500_SPI_TIMEOUT)) != HAL_SPI_ERROR_NONE)) goto W5500_REG_READ_BYTE_RET;
if(((HAL_SPI_ERROR_STATE = HAL_SPI_Receive(&W5500_SPI_PORT, &r_DataPhase, sizeof(uint8_t), W5500_SPI_TIMEOUT)) != HAL_SPI_ERROR_NONE)) goto W5500_REG_READ_BYTE_RET;

#endif

return r_DataPhase;

W5500_REG_READ_BYTE_RET:
return HAL_SPI_ERROR_STATE;
```

}

This function works well with reading bytes of the chip. But I can not get any values except 0x00 from Rx buffer memory.

Any help will be welcomed…
Regards

**Edit:**
Here is detailed information…
1- Here, I’ve set received size and received pointer values as 5 for initial value (to see if it changes later)
![cr1](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/3/36254735693a79406ffab19cd6c6b99ba62720f6.png)
2- Here, I connet to W5500 as TCP Client on port 5000

[![cr2](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/e/ede0f8c16c821eab83d0e68829ffff3d00c0947b.png) cr2628×547 24.1 KB](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/e/ede0f8c16c821eab83d0e68829ffff3d00c0947b.png)

3- As expected, the initial value of the received data size changes to ‘0’ after establishing communication with W5500
![cr3](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/9/98517a38ae84a5aad907ac7a3eb31f9f664164a2.png)
4- Then I send 4 bytes of “TEST” data from client.

[![cr7](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/b/ba3e702b04b7c41948e236329a68f97c269755e7.png) cr7630×546 25.1 KB](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/b/ba3e702b04b7c41948e236329a68f97c269755e7.png)

5- Received size becomes ‘4’ and pointer value becomes ‘0’ as epected and no problem so far.
![cr4](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/a/abbaaa555ebaf24b7903416b7a4ce8a449e63349.png)
6- Then I run this code:
for(uint16_t i = 0; i&lt;20; i++)
test_receive_buffer[i] = W5500_REG_READ_BYTE(SOCKET0_RX_BUFFER, i);
7- Result is:
![cr6](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/9/9d548ba8927a3e5c6086cad3e6b762242853860e.png)
8- After reading buffer, I check stock established register with the same read function and it works:
![cr5](https://maker.wiznet.io/forum_uploads/wiznet/original/2X/d/d1405dac1aa76070bc198e41b515353e2b9ff9b9.png)

Have you ever experienced something like this before?

## Replies

### Reply 1 by nocturnal, 2018-01-06

Ok,
I must admit that it was my mistake!!
my control phase was 0x88 instead of 0x18! because of mistaken definition.

Meanwhile, we’ve met and we’ll become wiznet friends from now on ![:slight_smile:](https://emoji.discourse-cdn.com/twitter/slight_smile.png?v=12)

Thank you from now

---

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