Unable to send data through TCP (STM32L476RG with W5500)

Hello,

For a hobby project I’m trying to transfer data from my STM32L476RG board via the wiznet W5500 to my laptop by using TCP.
I allready did this with the UDP protocol which works perfectly, but with the TCP i’m stuck.

The W5500 functions as a client, the laptop as a server. Monitoring the trafic I do see that it is doing the ARP request. As well as that the register of the W5500 changes to connect, but it does not transfer any data.
Do you have any idea?

The code underneath is just a part. I did not include the declarations of all the IP adresses and ports. What I do in the top part is resetting the device and setting up the general register (sending 0x00).
I setup the w5500 ip to 192.168.1.1 (subnet 255.255.255.0). And the destination to 192.168.1.40.
Gates are 50000 and 51000 (sender / reciever).

On the below code I tried some variations: First opening, connecting and closing. Opening once, connecting once, sending data in loop, etc. But nothing helps to send the data. What am i missing?

  1. Setting up register
    //Socket Register (Socket Register 1) Selecting UDP mode
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);
    SOCKREG[0] = 0x00;
    SOCKREG[1] = 0x00;
    SOCKREG[2] = 0x2C; //Control command write socket reg. 1
    SOCKREG[3] = 0x01; //0b00000010 (selecting UDP mode)
    HAL_SPI_Transmit(&hspi1, SOCKREG, 4, HAL_MAX_DELAY);
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET);
    //HAL_Delay(10);

uint8_t i = 0x00;
uint8_t j = 0xFF;
uint8_t d = 0x10;

/* USER CODE END 2 */

/* Infinite loop /
/
USER CODE BEGIN WHILE */
while (1)
{
//Open command
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);
OPENCMD[0] = 0x00;
OPENCMD[1] = 0x01;
OPENCMD[2] = 0x2C;
OPENCMD[3] = 0x01;
HAL_SPI_Transmit(&hspi1, OPENCMD, 4, HAL_MAX_DELAY);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET);
//HAL_Delay(10);

      	  //Connect command
      	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);
          OPENCMD[0] = 0x00;
          OPENCMD[1] = 0x01;
          OPENCMD[2] = 0x2C;
          OPENCMD[3] = 0x04;
          HAL_SPI_Transmit(&hspi1, OPENCMD, 4, HAL_MAX_DELAY);
          HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET);
          HAL_Delay(10);


      	  //Send data to TX socket 1 68656c6c6f
      	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);
      	  DATATX[0] = 0x10; //0x00
      	  DATATX[1] = 0x00; //0x40
      	  DATATX[2] = 0x34;
      	  DATATX[3] = d; //First byte of data that is going to be send.
      	  DATATX[4] = i; //Second byte of data
      	  DATATX[5] = j; //Second byte of data
      	  HAL_SPI_Transmit(&hspi1, DATATX, 6, HAL_MAX_DELAY);
      	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET);
      	  //HAL_Delay(10);

      	  //Send data to TX with TX_WR
      	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);
      	  DATATX2[0] = 0x00;
      	  DATATX2[1] = 0x24;
      	  DATATX2[2] = 0x2C;
      	  DATATX2[3] = 0x00; //amount of bytes send
      	  DATATX2[4] = 0x03; //amount of bytes send
      	  HAL_SPI_Transmit(&hspi1, DATATX2, 5, HAL_MAX_DELAY);
      	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET);
      	  //HAL_Delay(10);

      	  //Socket command register [0x0001]
      	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);
      	  SOCKTRANS[0] = 0x00;
      	  SOCKTRANS[1] = 0x01;
      	  SOCKTRANS[2] = 0x2C; //Control command write socket reg. 1
      	  SOCKTRANS[3] = 0x20; //SEND command 20 SEND & 21 SEND MAC
      	  HAL_SPI_Transmit(&hspi1, SOCKTRANS, 4, HAL_MAX_DELAY);
      	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET);
      	  //HAL_Delay(10);

      	  //Close socket
      	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_RESET);
      	  SOCKCLS[0] = 0x00;
      	  SOCKCLS[1] = 0x01;
      	  SOCKCLS[2] = 0x2C;
      	  SOCKCLS[3] = 0x10; //Close command
      	  HAL_SPI_Transmit(&hspi1, SOCKCLS, 4, HAL_MAX_DELAY);
      	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_6, GPIO_PIN_SET);

      	  if (d == 0x10)
      	  {
      		  d++;
      	  }

      	  else
      	  {
      		  d--;
      	  }

      	  i ++;
      	  j --;

      	  HAL_Delay(1000);