Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Existing members must set a new password through the “I forgot my password” button in theProducts

MakerCommunity login ​
Wiki
window. E-Sale
Click the link to learn more about how to do it!

W5500 UDP problem

Ashikur maj ’17

I am trying to interface W5500 with STM32f103c8t6 using UDP . Problem is I can’t send data
trough UDP socket but I can receive data from the UDP socket . Please help me to solve the
problem

Thank you

Kei Contributor maj ’17

There is not enough information in the question.

You have now written a question on the W5500 Ethernet Shield category. Are you using the
W5500 Ethernet Shield?

Anyway, we need to know what code you used to help you.


In addition, we need information about what settings you have set up to send and receive data.

Sachin_Singh jun ’17

Hi i have following Wiznet W5100 board

http://www.ebay.in/itm/112321091012?aff_source=Sok-Goog

and i am interfacing it following STM32 Board using UDP

STM32VLDISCOVERY - STMicroelectronics
STM32VLDISCOVERY - Discovery kit with STM32F100RB MCU, STM32VLDISCOVERY,
STMicroelectronics

I am trying to make an Echo server. Whatever data is sent to my chip via W5500 , data is returned
back to the PC. I have a C# program written by myself to send and receive data using UDP
socket. I am Monitoring communication by Wireshark. UDP send from PC is working ok. i can see
themain
Skip to datacontent
sent in wireshark and data is received without any problem in my C program. But when i
send the data back to the PC, Function SendData is stuck inside while(1) loop
such that Sok_0_INTR_Value is always 0x04. I neither get timeout or send_ok.Please drop me a
word if possible MakerCommunity Products Wiki
Thank You

#define BSB_Common_Reg 0b00000 // Block Selection Bits - Common Reg


#define BSB_Sok_0_Reg 0b00001

#define Wiz_CS GPIO_Pin_3 // Port A


#define Wiz_RST GPIO_Pin_2 // Port A

unsigned volatile char DataRecieved = 0 ; // To be changed by Socket Interrupt


int main(void)
{
LEDSetup();
SPI1_setup();
ExtInterruptLineConfig();
Wiz_Setup_A_INIT();
Wiz_Setup_B_OPEN();

unsigned short RecvCount = 0 ;


unsigned short Count = 0 ;
unsigned char Data[64];
unsigned char SCADAInfo[8];

while(1)
{
GPIO_SetBits(GPIOC, GPIO_Pin_8 | GPIO_Pin_9 );
Delay(1,500);
GPIO_ResetBits(GPIOC, GPIO_Pin_8 | GPIO_Pin_9 );
Delay(1,500);
RecvCount = DataRecievedCheck();
if( RecvCount )
{
GetData(Data , &Count ,SCADAInfo); // Recieve Data
SendData(Data ,Count );
__disable_irq();
RecvCount = 0 ; // Atomic
__enable_irq();
Wiz_Setup_B_OPEN(); // Wiz UDP = Open-Close Socket every Time. Bu
}
}
return 1 ;
}
void Wiz_Setup_A_INIT(void)
{
unsigned short GAR = 0x0001 ; // Gateway 4 Bytes
unsigned short SUBR = 0x0005 ; // Subnet 4 Bytes
unsigned short SAR = 0x0009 ; // Source Hardware Address MAC - 6 Bytes
unsigned short SIPR = 0x000F ; // IP Address 4 Bytes
unsigned short RCR = 0x001B ; // Retry Count, Retry Attempts = RCR + 1,
unsigned
Skip to main content short SIMR = 0x0016 ; // Socket Interrupt Mask , Only enable for
// Reset
Delay(1,200); MakerCommunity Products Wiki
GPIO_ResetBits(GPIOA, Wiz_RST);
Delay(1,5); // Reset Time = 1.5 Mili Sec
GPIO_SetBits(GPIOA, Wiz_RST);
Delay(1,2);

// Auto Negotionaion = 2 Chips decide their Speed ( 10 / 100 MBPs ) and Du


// Link = Up => Auto Negotiation is success
// unsigned short PHYCFGR = 0x002E ;
// unsigned char PHYCFGRValue = 0x00 ; // If PHYCFGRValue && 0x01 = 1
// while( ( PHYCFGRValue & 0x01) != 0 ) // 0Th bit of PHYCFGR Reg = 1
// Wiz_Read_Multi( PHYCFGR , BSB_Common_Reg , &PHYCFGRValue , 1);

// Mode Reg = 0x00 after Reset = ok


unsigned char mac[] = {0x00,0x16,0x36,0xDE,0x58,0xF6};
unsigned char ip[] = {192,168,1,12}; // 0xC0 , 0xA8 , 0x01 , 0x0C
unsigned char subnet[] = {255,255,255,0}; // 255 = 0xFF
unsigned char gate[] = {192,168,1,1};

Wiz_Write_Multi(SAR , BSB_Common_Reg , mac , sizeof(mac));


Wiz_Write_Multi(SIPR , BSB_Common_Reg , ip, sizeof(ip));
Wiz_Write_Multi(SUBR , BSB_Common_Reg , subnet , sizeof(subnet));
Wiz_Write_Multi(GAR , BSB_Common_Reg , gate , sizeof(gate));

unsigned char RCRValue = 0x02 ; // Retry Count = 0x02 + 1 = 3


Wiz_Write_Multi(RCR , BSB_Common_Reg , &RCRValue , sizeof(RCRValue));
// Default RTR Retry Time At Reset = 2000 = 2000 x 0.1 = 200 MiLi Sec = OK
// Default IMR Interrupt Mask Reg = 0x00 = All Desabled = OK

unsigned char SIMRValue = 0x01 ; // Socket Interrupt Mask keep Socket Inte
Wiz_Write_Multi(SIMR , BSB_Common_Reg , &SIMRValue , sizeof(SIMRValue))
}
void Wiz_Setup_B_OPEN(void)
{
unsigned short Sok_0_Mod_Reg = 0x0000 ; // Mode Offet Address
unsigned char Sok_0_Mod_Value = 0x02 ; // Sock 0 Mode = 0x22 = UDP

unsigned short Sok_0_Port_Reg = 0x0004 ; // 2 Bytes - Sock 0 Port Offset A


unsigned char port[] = {0x13,0x88}; // 0x1388 = 5000

unsigned short Sok_0_Comand_Reg = 0x0001 ; //


unsigned char Comand_OPEN = 0x01 ; // Command Reg = 0x01 => Socket OPEN
unsigned char Comand_CLOSE = 0x10 ; // Command Reg = 0x10 => Socket CLOSE

unsigned short Sok_0_Status_Reg = 0x0003 ;


unsigned char Status Socket = 0x00 ; // => 0x02 = UDP

Sachin_Singh jun ’17

Skip to main content


Hi i have following Wiznet W5100 board MakerCommunity Products Wiki

* http://www.ebay.in/itm/112321091012?aff_source=Sok-Goog

and i am interfacing it following STM32 Board using UDP

* http://www.st.com/en/evaluation-tools/stm32vldiscovery.html

I am trying to make an Echo server. Whatever data is sent to my chip via W5500 , data is returned
back to the PC. I have a C# program written by myself to send and receive data using UDP
socket. I am Monitoring communication by Wireshark. UDP send from PC is working ok. i can see
the data sent in wireshark and data is received without any problem in my C program. But when i
send the data back to the PC, Function SendData is stuck inside while(1) loop such that
Sok_0_INTR_Value is always 0x04. I neither get timeout or send_ok. Physically there is a direct
connection by patch cable between W5500 and my laptop. and w5500 gateway defined as laptop
IP
Thank You

#include<stm32f10x.h>
#include<stm32f10x_gpio.h>

#define BSB_Common_Reg 0b00000 // Block Selection Bits - Common Reg


#define BSB_Sok_0_Reg 0b00001

#define Wiz_CS GPIO_Pin_3 // Port A


#define Wiz_RST GPIO_Pin_2 // Port A

unsigned volatile char DataRecieved = 0 ; // To be changed by Socket Interrupt


int main(void)
{
SPI1_setup();
Wiz_Setup_A_INIT();
Wiz_Setup_B_OPEN();

unsigned short RecvCount = 0 ;


unsigned short Count = 0 ;
unsigned char Data[64];
unsigned char SCADAInfo[8];

while(1)
{
GPIO_SetBits(GPIOC, GPIO_Pin_8 | GPIO_Pin_9 );
Delay(1,500); // 500 Mili Sec
GPIO_ResetBits(GPIOC, GPIO_Pin_8 | GPIO_Pin_9 );
Delay(1,500); // 500 Mili Sec
RecvCount = DataRecievedCheck();
if( RecvCount )
{
GetData(Data , &Count ,SCADAInfo); // Recieve Data = Closes Soket
Skip to main content SendData(Data ,Count ); // Send Data = Closes Soket in
__disable_irq();
RecvCount = 0 ; // Atomic
__enable_irq(); MakerCommunity Products Wiki
Wiz_Setup_B_OPEN(); // Wiz UDP = Open-Close Socket every Time. Bu
}
}
return 1 ;
}
void Wiz_Setup_A_INIT(void)
{
unsigned short GAR = 0x0001 ; // Gateway 4 Bytes
unsigned short SUBR = 0x0005 ; // Subnet 4 Bytes
unsigned short SAR = 0x0009 ; // Source Hardware Address MAC - 6 Bytes
unsigned short SIPR = 0x000F ; // IP Address 4 Bytes
unsigned short RCR = 0x001B ; // Retry Count, Retry Attempts = RCR + 1,
unsigned short SIMR = 0x0016 ; // Socket Interrupt Mask , Only enable for

// Reset
Delay(1,200); // 200 Mili Sec
GPIO_ResetBits(GPIOA, Wiz_RST);
Delay(1,5); // Reset Time = 1.5 Mili Sec
GPIO_SetBits(GPIOA, Wiz_RST);
Delay(1,2); // 2 mili sec

// Auto Negotionaion = 2 Chips decide their Speed ( 10 / 100 MBPs ) and Du


// Link = Up => Auto Negotiation is success
// unsigned short PHYCFGR = 0x002E ;
// unsigned char PHYCFGRValue = 0x00 ; // If PHYCFGRValue && 0x01 = 1
// while( ( PHYCFGRValue & 0x01) != 0 ) // 0Th bit of PHYCFGR Reg = 1
// Wiz_Read_Multi( PHYCFGR , BSB_Common_Reg , &PHYCFGRValue , 1);

// Mode Reg = 0x00 after Reset = ok


unsigned char mac[] = {0x00,0x16,0x36,0xDE,0x58,0xF6};
unsigned char ip[] = {192,168,1,12}; // 0xC0 , 0xA8 , 0x01 , 0x0C
unsigned char subnet[] = {255,255,255,0}; // 255 = 0xFF
unsigned char gate[] = {192,168,1,1};
// Direct connection by patch cable between W5500 and laptop.

Wiz_Write_Multi(SAR , BSB_Common_Reg , mac , sizeof(mac));


Wiz_Write_Multi(SIPR , BSB_Common_Reg , ip, sizeof(ip));
Wiz_Write_Multi(SUBR , BSB_Common_Reg , subnet , sizeof(subnet));
Wiz_Write_Multi(GAR , BSB_Common_Reg , gate , sizeof(gate));

unsigned char RCRValue = 0x02 ; // Retry Count = 0x02 + 1 = 3


Wiz_Write_Multi(RCR , BSB_Common_Reg , &RCRValue , sizeof(RCRValue));
// Default RTR Retry Time At Reset = 2000 = 2000 x 0.1 = 200 MiLi Sec = OK
// Default IMR Interrupt Mask Reg = 0x00 = All Desabled = OK

unsigned char SIMRValue = 0x01 ; // Socket Interrupt Mask keep Socket Inte
Wiz_Write_Multi(SIMR , BSB_Common_Reg , &SIMRValue , sizeof(SIMRValue))
}
Skip tovoid
mainWiz_Setup_B_OPEN(void)
content
{
unsigned short Sok_0_Mod_Reg = 0x0000 ; // Mode Offet Address
unsigned char Sok_0_Mod_Value = 0x02 ; // Sock 0 MakerCommunity
Mode = 0x22 = UDPProducts Wiki

unsigned short Sok_0_Port_Reg = 0x0004 ; // 2 Bytes - Sock 0 Port Offset A


unsigned char port[] = {0x13,0x88}; // 0x1388 = 5000

unsigned short Sok_0_Comand_Reg = 0x0001 ; //


unsigned char Comand_OPEN = 0x01 ; // Command Reg = 0x01 => Socket OPEN
unsigned char Comand CLOSE = 0x10 ; // Command Reg = 0x10 => Socket CLOSE

Sachin_Singh jun ’17

This is a working UDP code both by polling and interrupt , tested on STM32F100RB

#include<stm32f10x.h>
#include<stm32f10x_gpio.h>
#include<stm32f10x_rcc.h>
#include<stm32f10x_usart.h>
#include<stm32f10x_tim.h>
#include<stm32f10x_spi.h>
#include<stm32f10x_exti.h>
#include<misc.h>

// ip.addr == 192.168.1.12

void Wiz_Write_Multi( unsigned short , unsigned char , unsigned char * , u


void Wiz_Read_Multi( unsigned short , unsigned char , unsigned char *, uns
void LEDSetup(void);
void SPI1_setup(void);
void SPI_SendBye(unsigned char);
unsigned char SPI_ReadByte();
void Tim2_init(unsigned char);
void Delay( unsigned char , unsigned short); // 0 = Micro , 1 = Mili
void Wiz_Setup_A_INIT(void);
void Wiz_Setup_B_OPEN(void);
void ExtInterruptLineConfig(void) ;
void GetData(unsigned char* , unsigned short* , unsigned char*);
unsigned char SendData(unsigned char* , unsigned short);
unsigned short DataRecievedCheck(void);

#define BSB_Common_Reg 0b00000 // Block Selection Bits - Common Reg


#define BSB_Sok_0_Reg 0b00001

#define Wiz_CS GPIO_Pin_3 // Port A


#define Wiz_RST GPIO_Pin_2 // Port A
// __disable_irq();RecvCount = 0 ; // Atomic __enable_irq();
unsigned volatile char DataRecieved = 0 ; // To be changed by Socket Inter
int main(void)
{
LEDSetup();
Skip to main content
SPI1_setup();
ExtInterruptLineConfig();
Wiz_Setup_A_INIT();
Wiz_Setup_B_OPEN(); MakerCommunity Products Wiki

unsigned short RecvCount = 0 ;


unsigned short Count = 0 ;
unsigned char Data[64];
unsigned char SCADAInfo[8];

while(1)
{
GPIO_SetBits(GPIOC, GPIO_Pin_8 | GPIO_Pin_9 );
Delay(1,500);
GPIO_ResetBits(GPIOC, GPIO_Pin_8 | GPIO_Pin_9 );
Delay(1,500);
// RecvCount = DataRecievedCheck(); // if( RecvCount ) Polling
if( DataRecieved ) // Interrupt
{
DataRecieved = 0 ;
GetData(Data , &Count ,SCADAInfo); // Recieve Data = Closes S
Wiz_Setup_B_OPEN();
SendData(Data ,Count ); // Send Data = Closes Soke
Wiz_Setup_B_OPEN(); // Wiz UDP = Open-Close Socket every Time
}
}
return 1 ;
}
void Wiz_Setup_A_INIT(void)
{
unsigned short GAR = 0x0001 ; // Gateway 4 Bytes
unsigned short SUBR = 0x0005 ; // Subnet 4 Bytes
unsigned short SAR = 0x0009 ; // Source Hardware Address MAC - 6 Byt
unsigned short SIPR = 0x000F ; // IP Address 4 Bytes
unsigned short RCR = 0x001B ; // Retry Count, Retry Attempts = RCR +
unsigned short SIMR = 0x0018 ; // Socket Interrupt Mask , Only enable

// Reset
Delay(1,200);
GPIO_ResetBits(GPIOA, Wiz_RST);
Delay(1,5); // Reset Time = 1.5 Mili Sec
GPIO_SetBits(GPIOA, Wiz_RST);
Delay(1,2);

// Auto Negotionaion = 2 Chips decide their Speed ( 10 / 100 MBPs ) an


// Link = Up => Auto Negotiation is success
// unsigned short PHYCFGR = 0x002E ;
// unsigned char PHYCFGRValue = 0x00 ; // If PHYCFGRValue && 0x01
// while( ( PHYCFGRValue & 0x01) != 0 ) // 0Th bit of PHYCFGR Reg =
// Wiz_Read_Multi( PHYCFGR , BSB_Common_Reg , &PHYCFGRValue , 1);

// Mode Reg = 0x00 after Reset = ok


unsigned char mac[] = {0x00,0x16,0x36,0xDE,0x58,0xF6};
Skip to main content
unsigned char ip[] = {192,168,1,12}; // 0xC0 , 0xA8 , 0x01 , 0x0C
unsigned char subnet[] = {255,255,255,0}; // 255 = 0xFF
unsigned char gate[] = {192,168,1,8}; // My OwnMakerCommunity
laptop Products Wiki
// Direct connection by patch cable between W5500 and laptop. gateway

Kei Contributor jun ’17

Your question seems to have already been solved in the following article
Thank you for providing a good reference.

W5500 UDP Recieve Working but SEND not working

Thanks for quick repply, i managed to solve the issue I get PING reply from W5500. i was
making 3 mistakes (1) i was sending data on a UDP socket which was not open , and after
this Polling methd recieve and transmit started to work as expected GetData(Data , &Count
,SCADAInfo); Wiz_Setup_B_OPEN(); // This Line was missing SendData(Data ,Count );
Wiz_Setup_B_OPEN(); later i wanted to use interrupt which was not working but i found out
following error (2) …

Ashikur jul ’17

Thank you . Your code help me a lot

Sachin_Singh jul ’17

Well then develop the TCP code with Interrupt , test it and share it with me…

New & Unread Topics

Tema Odgovori Pregledi Aktivnosti

Implementing firmware update over the air (OTA) on STM32WB using


0 51 nov. ’23
wiznet w5500

Want to read more? Browse other topics in or view latest topics.

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.

You might also like