ioLibrary functions for w5500
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: ioLibrary functions for w5500
by becky ·
In the wizchip_conf.h, the following define should be set to W5500.

Thank you.
RE: RE: ioLibrary functions for w5500
by Deepak ·
Thank you for your reply.
I have already changed the defines for w5500 and it was not working that is why i doubt in these condition. But i found the problem was in uC spi configuration which in 4 bit, and i changed it to 8 bit and it worked.
But it is working in local network only, when i am trying to connect remote server connection is not establishing.
My code is given below : -
int main(void)
{
uint8_t rcvBuf[20], bufSize = { 2, 2, 2, 2, 2, 2, 2, 2};
uint8_t dest_ip[4]={147,71,205,253};
void cs_sel()
{
//SPI3_CS_H;
GPIOA->BRR|=GPIO_PIN_15;
}
void cs_desel()
{
//SPI3_CS_L;
}
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);
}
MX_GPIO_Init();
MX_SPI3_Init();
MX_USART2_UART_Init();
UARTSendString(2, “Ethernet start\n\r”);
GPIOA-> BSRR |= (1<<0); //Init pin
GPIOE-> BRR |= (1<<10); // Reset pin
HAL_Delay(400);
GPIOE-> BSRR |= (1<<10); // Reset pin
HAL_Delay(2000);
reg_wizchip_cs_cbfunc(cs_sel, cs_desel);
reg_wizchip_spi_cbfunc(spi_rb, spi_wb);
wizchip_init(bufSize, bufSize);
volatile wiz_NetInfo netInfo =
{
{0x00, 0x14, 0xA3, 0x75, 0x20, 0x3f}, // Source Mac Address
{192, 168, 1, 100}, // Source IP Address
{255, 255, 255, 0}, // Subnet Mask
{192, 168, 1,1}, // Gateway IP Address
{127,0,0,53}, // DNS server IP Address
NETINFO_STATIC
};
volatile wiz_PhyConf phyConf =
{
PHY_CONFBY_HW, // PHY_CONFBY_SW
PHY_MODE_AUTONEGO, // PHY_MODE_AUTONEGO
PHY_SPEED_100, // PHY_SPEED_100
PHY_DUPLEX_FULL, // PHY_DUPLEX_HALF
};
ctlnetwork(CN_SET_NETINFO, (void*) &netInfo);
HAL_Delay(500);
ctlwizchip(CW_SET_PHYCONF, (void*) &phyConf);
HAL_Delay(500);
wizchip_getnetinfo(&netInfo);
retry:
if((retVal = socket(0, Sn_MR_TCP, 5001, 0)) == 0) {
UARTSendString(2, “socket_created”);
HAL_Delay(800);
if((ret = connect(sock_id_tcp,dest_ip,0x30D4)) == SOCK_OK){
UARTSendString(2, “connected_stablish\r\n”);
HAL_Delay(500);
send(0, “Hello\r\n”, 7);
}
else{
UARTSendString(2, “connected not stablish\r\n”);
}
}
else{
UARTSendString(2, “socket not created”);
}
HAL_Delay(200);
goto retry;
while (1)
{
UARTSendString(2, " Inside while \r\n");
HAL_Delay(1000);
}
}
If i am trying to send data to local ip (192.168.1.24 configure as server using netcat command), It is working find . When i am trying to send data to remote server(147.71.205.253),It is not working.
But when i am sending data from my local network computer (192.168.1.48) to remote server using netcat command, It is sending data.
netcat - Netcat is a tool in linux to test the tcp client server connection. I know it is comman tool, instead i explain it.
Thank you.
RE: ioLibrary functions for w5500
by becky ·
W5500 can communicate with external network through gateway.
In order to communicate with the external network, port forwarding must be configured in the gateway.
Or, if an IP is assigned through DHCP, it can be managed by a DHCP server to communicate with an external network.
RE: ioLibrary functions for w5500
by Deepak ·
As i know port forwarding is necessary when someone want to connect to my local ip. If my need is to send data only, Is there also port forwarding necessary ??
And i am also able to send data from my local computer.
Please assist…
RE: ioLibrary functions for w5500
by becky ·
If you think the W5500 on the network is the same condition as the PC and there are no problems,
Make sure the SPI is set up properly
Please read and check if the set IP and MAC address are properly set.
RE: ioLibrary functions for w5500
by Deepak ·
As I mention earlier that I am able to connect and send data in local network. May I say SPI setup is proper and also IP and MAC address are properly set ??
If yes what should be my next step to identity the problem ??
RE: ioLibrary functions for w5500
by Alireza Najafi ·
Hi Deepak and everybody.
I have been trying to do a project about a local TCP server-client connection between my MCU and Laptop with W5500 module and stm32f4 discovery board. I have seen a number of tutorials and searched through many forums to learn how to configure IoLibrary and get it all working with the MCU. I even implemented the code you put here. But, I still can’t get it right. I’m confused and do not know what the problem is. I get no error while debugging the code, however, I’m not able to find the IP that I’m setting for my W5500 Module in the local network while pinging it. This is why I think I’m not setting W5500 module parameters correctly.
Can anyone help me with this? I’m somehow new to stm32.
------------------- Here is my Pin setting------------------------------
SPI1
MISO → PA6
MOSI → PA7
SCK → PA5
CS → PA1
Reset → PA0
------------------- Here is my Code------------------------------
/* Includes ------------------------------------------------------------------*/
#include “main.h”
#include “wizchip_conf.h”
#include “stdio.h”
#include “socket.h”
#include “w5500.h”
/* Private variables ---------------------------------------------------------*/
SPI_HandleTypeDef hspi1;
UART_HandleTypeDef huart2;
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI1_Init(void);
static void MX_USART2_UART_Init(void);
/* Private user code ---------------------------------------------------------/
/ USER CODE BEGIN 0 */
// For debugging through SWV with printf
int _write(int32_t file, uint8_t *ptr, int32_t len)
{
int i=0;
for(i=0 ; i<len ; i++)
ITM_SendChar((*ptr++));
return len;
}
uint8_t counter= 0;
int main(void)
{
/* USER CODE BEGIN 1 */
void cs_sel() {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET); //CS LOW
}
/* 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_SPI1_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
uint8_t rcvBuf[20], bufSize = {16, 0, 0, 0, 0,0,0,0};
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);
HAL_Delay(400);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);
HAL_Delay(2000);
reg_wizchip_cs_cbfunc(cs_sel, cs_desel);
reg_wizchip_spi_cbfunc(spi_rb, spi_wb);
wizchip_init(bufSize, bufSize);
volatile wiz_NetInfo netInfo =
{
{0x00, 0x14, 0xA3, 0x75, 0x20, 0x3f}, // Source Mac Address
{192, 168, 1, 100}, // Source IP Address
{255, 255, 255, 0}, // Subnet Mask
{192, 168, 1,1}, // Gateway IP Address
{127,0,0,53}, // DNS server IP Address
NETINFO_STATIC
};
volatile wiz_PhyConf phyConf =
{
PHY_CONFBY_HW, // PHY_CONFBY_SW
PHY_MODE_AUTONEGO, // PHY_MODE_AUTONEGO
PHY_SPEED_100, // PHY_SPEED_100
PHY_DUPLEX_FULL, // PHY_DUPLEX_HALF
};
ctlnetwork(CN_SET_NETINFO, (void*) &netInfo);
HAL_Delay(500);
ctlwizchip(CW_SET_PHYCONF, (void*) &phyConf);
HAL_Delay(500);
wizchip_getnetinfo(&netInfo);
while (1)
{
}
/* USER CODE END 3 */
}
RE: ioLibrary functions for w5500
by irina WIZnet ·
I think you can refer to the source code as below link.
Also I think you need to confirm the SPI communication whether or not.
You can try to read the VersionR(0x0039) register of w5500.
If SPI communication works normally, you can see the 0x04 as return value.
RE: ioLibrary functions for w5500
by Alireza Najafi ·
Hi dear Irina_kim.
Thanks a lot for your tips. I ran the get_VERSIONR command as the output came out to be 0x04. I also manage to set proper networkInfo on my module and verified they are written successfully. So I believe my SPI connection is working fine now.
There is one problem though. I can’t understand why my module is not responding to the ping command. I also WIRESHARKed it last night and found no trace of my module on the network.
Should I pay attention to my Ethernet configuration and set W5500 parameters in accordance to them or should I use the Wireless LAN parameters? I’m a little bit confused here.
I have chosen these parameters:
volatile wiz_NetInfo netInfo = {
{0x00, 0x08, 0xdc, 0xab, 0xcd, 0xef}, // Source Mac Address
{192, 168, 1, 199}, // Source IP Address {169, 254, 139, 2}
{255, 255, 255, 0}, // Subnet Mask
{192, 168, 1, 1}, // Gateway IP Address
{127,0,0,53}, // DNS server IP Address
NETINFO_STATIC
};
The response to ping command is:
Pinging 192.168.1.199 with 32 bytes of data:
Reply from 192.168.1.198: Destination host unreachable.
Reply from 192.168.1.198: Destination host unreachable.
Reply from 192.168.1.198: Destination host unreachable.
Reply from 192.168.1.198: Destination host unreachable. Ping statistics for 192.168.1.199:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
I have connected my module to my PC via a LAN cable.
My PC network config is :
Windows IP Configuration
Ethernet adapter Npcap Loopback Adapter:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::ac9d:9676:2497:8b28%22
Autoconfiguration IPv4 Address. . : 169.254.139.40
Subnet Mask . . . . . . . . . . . : 255.255.0.0
Default Gateway . . . . . . . . . :
Wireless LAN adapter Local Area Connection
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Wireless LAN adapter Local Area Connection
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Ethernet adapter Ethernet:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::dd6c:2501:3e57:477b%24
Autoconfiguration IPv4 Address. . : 169.254.71.123
Subnet Mask . . . . . . . . . . . : 255.255.0.0
Default Gateway . . . . . . . . . :
Ethernet adapter Ethernet 2:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix .
Wireless LAN adapter Wi-Fi:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::accd:a18d:8e11:1f1%19
IPv4 Address. . . . . . . . . . . : 192.168.1.198
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
Thanks a ton for your support and help.