Rx Buffer Always returns 0x00

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
2- Here, I connet to W5500 as TCP Client on port 5000


3- As expected, the initial value of the received data size changes to ‘0’ after establishing communication with W5500
cr3
4- Then I send 4 bytes of “TEST” data from client.

5- Received size becomes ‘4’ and pointer value becomes ‘0’ as epected and no problem so far.
cr4
6- Then I run this code:
for(uint16_t i = 0; i<20; i++)
test_receive_buffer[i] = W5500_REG_READ_BYTE(SOCKET0_RX_BUFFER, i);
7- Result is:
cr6
8- After reading buffer, I check stock established register with the same read function and it works:
cr5

Have you ever experienced something like this before?

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:

Thank you from now

1 Like