W5500 TCP Client Connect() is not working
Ethernet Chips
No replies yet. Be the first to reply.
Join the discussion.
Ethernet Chips
No replies yet. Be the first to reply.
Join the discussion.
Share projects and connect with makers.
Joined before the site update? first.
New to WIZnet Makers?
We sent a verification link to your address. Open it to activate your account, then log in.
Accounts from this email provider are reviewed by an administrator after verification. Approval usually takes one business day.
Already have an account?
Enter your email address. If it belongs to an account, we'll send a link to set a new password. Members who joined before the site update use this to set their password.
If an account uses that address, we sent a link to set a new password. The link works once and expires in 30 minutes.
Know your password?
Need an account?
RE: W5500 TCP Client Connect() is not working
by becky ·
If you use the WIZ850io module, the connection is enough.
Looking at the packet, the module is looking for a 192.168.1.5 server, but it does not receive a response.
This may not be a firmware issue
Check if you have a server and check the network environment.
RE: W5500 TCP Client Connect() is not working
by alperen erdogan ·
i checked network environment . But all its ok . i looked port . its opening with application . İ try close the firewall but its stay same position . not running . icant find why
RE: RE: W5500 TCP Client Connect() is not working
by becky ·
What is 192.168.1.5?
I can see the ARP packet sent by W5500, I think your PC and W5500 are connected.
If 192.168.1.5 is not a PC, check if the PC can connect to 192.168.1.5
RE: W5500 TCP Client Connect() is not working
by alperen erdogan ·
what is mean "check if the PC can connect to 192.168.1.5 " . 192.168.1.5 is my personal pc’s ip . im using win10 home .
RE: RE: W5500 TCP Client Connect() is not working
by becky ·
If your PC is 192.168.1.5, I think there is a problem with the PC environment. Your PC is not giving ARP Response. Turn off any firewalls, virtual machine programs or security programs.
RE: W5500 TCP Client Connect() is not working
by alperen erdogan ·
hi becky ,
I slightly modified my code.im using only Windows firewall for antivirus . The ip of my computer is 192.168.1.6 and the ip of wiznet is set to 192.168.1.5. I want to show you in the images how I did it :
My new Code :
/------------------------------------------------------------------/
/* USER CODE BEGIN Header /
/*
© Copyright (c) 2020 STMicroelectronics.
/
/ USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include “main.h”
/* Private includes ----------------------------------------------------------/
/ USER CODE BEGIN Includes /
#include “wizchip_conf.h”
#include “socket.h”
#include “loopback.h”
#include “string.h”
/ USER CODE END Includes */
/* Private typedef -----------------------------------------------------------/
/ USER CODE BEGIN PTD */
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------/
/ USER CODE BEGIN PD /
/ USER CODE END PD */
/* Private macro -------------------------------------------------------------/
/ USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
SPI_HandleTypeDef hspi3;
/* USER CODE BEGIN PV */
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI3_Init(void);
/ USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------/
/ USER CODE BEGIN 0 */
void cs_sel() {
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET); //CS LOW
}
void cs_desel() {
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET); //CS HIGH
}
uint8_t spi_rb(void) {
uint8_t rbuf;
HAL_SPI_Receive(&hspi3, &rbuf, 1, 0xFFFFFFFF);
return rbuf;
}
void spi_wb(uint8_t b) {
HAL_SPI_Transmit(&hspi3, &b, 1, 0xFFFFFFFF);
}
/* USER CODE END 0 */
/**
@brief The application entry point.
@retval int
/
int main(void)
{
/ USER CODE BEGIN 1 */
uint8_t bufSize = {2,2,2,2,2,2,2,2};
uint8_t s ;
s = 0 ;
uint8_t server_ip[4] = {192,168,1,6} ; // My PC’s new IP address .
uint8_t Baglan = 10 ; // when w5500 connect to pc correctly , this count going to “0” .
uint16_t socket_port = 5656 ; // port
uint16_t server_port = 5656 ; // port
uint16_t ret=2 ; // when socket is work correctly , this count going to “sucket number”
/*
*
int8_t memsize[2][8] = {{2,2,2,2,2,2,2,2},{2,2,2,2,2,2,2,2}};
uint8_t rec_buf [20];
*/
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals /
MX_GPIO_Init();
MX_SPI3_Init();
/ USER CODE BEGIN 2 */
reg_wizchip_cs_cbfunc(cs_sel, cs_desel);
reg_wizchip_spi_cbfunc(spi_rb, spi_wb);
wizchip_init(bufSize,bufSize);
wiz_NetInfo netInfo = { .mac = {0x00, 0x08, 0xdc, 0xab, 0xcd, 0xef}, // Mac address
.ip = {192, 168, 1, 5}, // w5500 IP address
.sn = {255, 255, 255,0}, // Subnet mask
.gw = {192, 168, 1,1}}; // Gateway address
wizchip_setnetinfo(&netInfo);//set IP address
wizchip_getnetinfo(&netInfo);
/------TIMEOUT CONFIG-----/
wiz_NetTimeout gWIZNETTIME = {.retry_cnt = 3, //RCR = 3
.time_100us = 2000}; //RTR = 2000
ctlnetwork(CN_SET_TIMEOUT,(void*)&gWIZNETTIME);
ctlnetwork(CN_GET_TIMEOUT, (void*)&gWIZNETTIME);
/* USER CODE END 2 */
/* Infinite loop /
/ USER CODE BEGIN WHILE */
while (1)
{
}
/* USER CODE END 3 */
}
/**
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Initializes the CPU, AHB and APB busses clocks
/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/* Initializes the CPU, AHB and APB busses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
}
/**
*/
static void MX_SPI3_Init(void)
{
/* USER CODE BEGIN SPI3_Init 0 */
/* USER CODE END SPI3_Init 0 */
/* USER CODE BEGIN SPI3_Init 1 */
/* USER CODE END SPI3_Init 1 /
/ SPI3 parameter configuration*/
hspi3.Instance = SPI3;
hspi3.Init.Mode = SPI_MODE_MASTER;
hspi3.Init.Direction = SPI_DIRECTION_2LINES;
hspi3.Init.DataSize = SPI_DATASIZE_8BIT;
hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi3.Init.NSS = SPI_NSS_SOFT;
hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi3.Init.TIMode = SPI_TIMODE_DISABLE;
hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi3.Init.CRCPolynomial = 7;
hspi3.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi3.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
if (HAL_SPI_Init(&hspi3) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI3_Init 2 */
/* USER CODE END SPI3_Init 2 */
}
/**
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0|CS_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);
/*Configure GPIO pins : PA0 CS_Pin */
GPIO_InitStruct.Pin = GPIO_PIN_0|CS_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : PB0 */
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
/* USER CODE BEGIN 4 */
/* USER CODE END 4 */
/**
/
void Error_Handler(void)
{
/ USER CODE BEGIN Error_Handler_Debug /
/ User can add his own implementation to report the HAL error return state */
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
*/
void assert_failed(uint8_t file, uint32_t line)
{
/ USER CODE BEGIN 6 /
/ User can add his own implementation to report the file name and line number,
tex: printf(“Wrong parameters value: file %s on line %d\r\n”, file, line) /
/ USER CODE END 6 /
}
#endif / USE_FULL_ASSERT */
/************************ (C) COPYRIGHT STMicroelectronics *END OF FILE/
/----------------------------/
And I turned of firewall like this :
I test the operation of my device as follows. I am using ‘breakpoint’ on the stm32cubeide application. I then examine the values that connect () 'gives me. The return values I constantly see are similar.
My errors decimal values = -3 , -4 , -13 .the code initially gives “-4” and sometimes “-13” as an error. And then he always gives the error “-3” and gets stuck.
My wireshark ss and description of the errors in the driver :
RE: W5500 TCP Client Connect() is not working
by alperen erdogan ·
i fix it the problem
thank you for all becky !
RE: W5500 TCP Client Connect() is not working
by sadhu ·
Dear alperen,
can you explain how u fixed the issue.i am facing same problem.
thank u.
RE: RE: W5500 TCP Client Connect() is not working
by alperen erdogan ·
Hi sadhu,
This problem about the FANTASTIC WINDOWS. This issue coming from FANTASTIC WINDOWS FIREWALL. And solution do not use windows. When i used my personel home modem, fix all of bugs errors. All of thing. Connect your wiznet module to your home modem or your router or something like that. If u connect to directly your PC, you can not use this module. Because FANTASTIC WINDOWS FIREWALL.
This project was my first embedded project. And now i am embedded software engineer. So interesting for me your message