WIZnet Developer Forum

W5100 internet problem

hello
i have setup the w5100 with an xmega microcontroller and i write a software to create http requests on a webserver port 8083

works fine no problme on internal network… but when i trey to my second server on external network i get no answer…

the gateway and server register that stores the ips is corect! with my pc on the same network than w5100 i can access the external server on port 8083

i beleve the w5100 needs some other configuration…
please help :wink:

Hi,
you also set the MAC address? (SHAR0 / SHAR5)

Yes I have set mac, if I request to lan server works fine,

Hi,
The server tries to connect is inside your LAN and is exposed on the Internet with public address … is it?
Try connecting to another internet server that is not physically connected to your LAN.
It could also be due to the router and unfortunately not enough to say “but I connect with the PC”.
It happened the same thing but if I linked in internet on a different internet connection everything worked… I have solved by replacing router that somehow was confusion in request forwarding perhaps due to an ARP problem in the LAN that I was never able to solve.

no
i have 2 servers! one in my lan and one in the internet! the internet is not physically connected to my lan

but also i try to request google.com ip and try to get some response but i get nothing, basicly any ip i request to internet i dont get reply, i try one other router and i have the same problem!

You have to understand if it is a request or response problem.
Have you checked with a dump the intermediate state of the socket?
Are you sure you do not have a change of state on the socket?
Otherwise it is left to figure out where are finishing your packets with wireshark.

i use use this function to connect and when try to connect stops to part:
else
{
glcd_clear();
sprintf(lcd_buffer,"— S0_SR = %u \r\n" ,SPI_Read(S0_SR));
glcd_outtextxy(0,0, lcd_buffer);
sprintf(lcd_buffer,"— S0_IR = %u \r\n" ,SPI_Read(S0_IR));
glcd_outtextxy(0,10, lcd_buffer);
delay_ms(500);
}

and in lcd i get:
S0_SR=1
S0_IR=8

uint8_t connect(uint8_t sock)
{
uint8_t retval = 0;
uint8_t eth_protocol;
uint16_t tcp_port;
eth_protocol =MR_TCP;
tcp_port =TCP_PORT;

if (sock != 0) return retval;

// Make sure we close the socket first
if (SPI_Read(S0_SR) == SOCK_CLOSED)
{
close(sock);
}
// Assigned Socket 0 Mode Register
SPI_Write(S0_MR,eth_protocol);

SPI_Write(S0_DIPR + 0,5);
SPI_Write(S0_DIPR + 1,144);
SPI_Write(S0_DIPR + 2,194);
SPI_Write(S0_DIPR + 3,228);

// Now open the Socket 0
SPI_Write(S0_DPORT0,((tcp_port & 0xFF00) >> 8 ));
SPI_Write(S0_DPORT0 + 1,(tcp_port & 0x00FF));
SPI_Write(S0_CR,CR_OPEN);
//delay_ms(50);

SPI_Write(S0_CR,CR_CONNECT);

delay_ms(150);

if (sock != 0) return retval;

if (SPI_Read(S0_SR) == SOCK_ESTABLISHED)
{
glcd_clear();
glcd_outtextxy(0,0, “socet connect”);
delay_ms(500);

                                    }

else
if (SPI_Read(S0_SR) == SOCK_CLOSED)
{
glcd_clear();
glcd_outtextxy(0,0, “socet time out”);
delay_ms(500);
socket_status_for_error=2;
}
else
{
glcd_clear();
sprintf(lcd_buffer,"— S0_SR = %u \r\n" ,SPI_Read(S0_SR));
glcd_outtextxy(0,0, lcd_buffer);
sprintf(lcd_buffer,"— S0_IR = %u \r\n" ,SPI_Read(S0_IR));
glcd_outtextxy(0,10, lcd_buffer);
delay_ms(500);
}

return retval;
}

It seems that it can not find the server and exits for timeout.
Are you using interrupts?

no im not using interupt…
if i change to lan ip 192.168.1.3 without any other change thay conect to my lockal server
is any other configuration? for gateway?

eeprom uint8_t mac_addr[] = {0xAD,0x16,0x36,0x11,0x52,0x35}; //se settings menu 4

eeprom char ip_addr[] = {192,168,1,102}; //se settings menu 5
eeprom char sub_mask[] = {255,255,255,0}; //se settings menu 6
eeprom char gtw_addr[] = {192,168,1,1}; //se settings menu 7

void W5100_Init(void)
{
// Ethernet Setup
// Setting the Wiznet W5100 Mode Register: 0x0000
SPI_Write(MR,0x80); // MR = 0b10000000;

// Setting the Wiznet W5100 Source Address Register (SAR): 0x0009 to 0x000E
SPI_Write(SAR + 0,mac_addr[0]);
SPI_Write(SAR + 1,mac_addr[1]);
SPI_Write(SAR + 2,mac_addr[2]);
SPI_Write(SAR + 3,mac_addr[3]);
SPI_Write(SAR + 4,mac_addr[4]);
SPI_Write(SAR + 5,mac_addr[5]);

// Setting the Wiznet W5100 IP Address (SIPR): 0x000F to 0x0012
SPI_Write(SIPR + 0,ip_addr[0]);
SPI_Write(SIPR + 1,ip_addr[1]);
SPI_Write(SIPR + 2,ip_addr[2]);
SPI_Write(SIPR + 3,ip_addr[3]);

// Setting the Wiznet W5100 Sub Mask Address (SUBR): 0x0005 to 0x0008
SPI_Write(SUBR + 0,sub_mask[0]);
SPI_Write(SUBR + 1,sub_mask[1]);
SPI_Write(SUBR + 2,sub_mask[2]);
SPI_Write(SUBR + 3,sub_mask[3]);

//Setting the Wiznet W5100 Gateway Address (GAR): 0x0001 to 0x0004
SPI_Write(GAR + 0,gtw_addr[0]);
SPI_Write(GAR + 1,gtw_addr[1]);
SPI_Write(GAR + 2,gtw_addr[2]);
SPI_Write(GAR + 3,gtw_addr[3]);

// Setting the Wiznet W5100 RX and TX Memory Size (2KB),
SPI_Write(RMSR,NET_MEMALLOC);
SPI_Write(TMSR,NET_MEMALLOC);

}

Try to act on these two registers although I honestly I never needed :
RTR (Retry Time-value Register) [R/W] [0x0017 – 0x0018] [0x07D0] page 22 (default is 200ms)
RCR (Retry Count Register) [R/W] [0x0019] [0x08] page 23

No,
IP, GW, mask and MAC … you have them setup, then it works locally.

It is left to figure out where are finishing your packets with wireshark.

the wireshark is packet sniffer? but if im not mistaken i need a hub no switch to get a copy to my pc…

also i try the RTR RCR and same resault…

… it is as if it could not find the gateway… a strange problem.
I try to review your source.

Are you sure mac_addr [] is different from 0 right?
PS: for wireshark you must have an hub or an hub/switch that supports “port mirroring”

finaly i found an old hub, i have xonect to port1 the w5100 (have 192.168.1.102 ip and mac AD:16:36:11:52:35)
on port 2 my pc (have 192.168.1.22 ip) and port 3 my linksys cisco router (192.168.1.1 ip)

i get some packets and i have save the file to attach zip file if you can take a look

on every request i get some lines
38 7.651239000 ad:16:36:11:52:35 Broadcast ARP 60 Who has 192.168.1.1? Tell 192.168.1.102

what you mean “Are you sure mac_addr is different from 0 right?”

thanks in advance
packet sniffer data.zip (2.3 KB)

hi,
from what I see the problem is the resolution of the gateway It seems between the W5100 and the router.
As you can see from the dump a few lines below the ARP packet sent from 192.168.1.22 the router contains a MAC address correct destination but if the W5100 sends the MAC is FF: FF: FF: FF: FF: FF.
With “Are you sure mac_addr is different from 0 right?” I mean if you’re sure that mac_addr is set (as I see in dump now).
I remember that there are some comments in the source just about ARP in setSUBR(), clearSUBR() and applySUBR() used in Socket.connect() and Socket.sendto()
Take a look here [url]ARP Problem]


This may be the problem http://www.wiznet.co.kr/wp-content/uploads/wiznethome/Chip/W5100/Document/3150Aplus_5100_ES_V250E.pdf
If you see at page 4 :

So set the subnet mask register to “FF.FF.FF.xx” and keeping it but save the
right subnet mask value to the global variable when you initialize the W5100.
When you use connect command in TCP or send command in UDP, set the
subnet mask register to zero using the variable before executing connect or
send command. After done connect or send command, sets the subnet mask
register again to keep its value to “FF.FF.FF.xx”.

If it is already so let me know.

i try this code! but i have the same , basicly dont work eather but i have now diffrent pacjet information

void W5100_Init(void)
{
// Ethernet Setup
// Setting the Wiznet W5100 Mode Register: 0x0000
SPI_Write(MR,0x80); // MR = 0b10000000;

// Setting the Wiznet W5100 Source Address Register (SAR): 0x0009 to 0x000E
SPI_Write(SAR + 0,mac_addr[0]);
SPI_Write(SAR + 1,mac_addr[1]);
SPI_Write(SAR + 2,mac_addr[2]);
SPI_Write(SAR + 3,mac_addr[3]);
SPI_Write(SAR + 4,mac_addr[4]);
SPI_Write(SAR + 5,mac_addr[5]);

// Setting the Wiznet W5100 IP Address (SIPR): 0x000F to 0x0012
SPI_Write(SIPR + 0,ip_addr[0]);
SPI_Write(SIPR + 1,ip_addr[1]);
SPI_Write(SIPR + 2,ip_addr[2]);
SPI_Write(SIPR + 3,ip_addr[3]);

// Setting the Wiznet W5100 Sub Mask Address (SUBR): 0x0005 to 0x0008
SPI_Write(SUBR + 0,0);
SPI_Write(SUBR + 1,0);
SPI_Write(SUBR + 2,0);
SPI_Write(SUBR + 3,0);

// Setting the Wiznet W5100 Gateway Address (GAR): 0x0001 to 0x0004
SPI_Write(GAR + 0,gtw_addr[0]);
SPI_Write(GAR + 1,gtw_addr[1]);
SPI_Write(GAR + 2,gtw_addr[2]);
SPI_Write(GAR + 3,gtw_addr[3]);

// Setting the Wiznet W5100 RX and TX Memory Size (2KB),
SPI_Write(RMSR,NET_MEMALLOC);
SPI_Write(TMSR,NET_MEMALLOC);

}

in initialization i set subnet to 0.0.0.0

and on connect function

uint8_t connect(uint8_t sock)
{
uint8_t retval = 0;
uint8_t eth_protocol;
uint16_t tcp_port;
eth_protocol =MR_TCP;
tcp_port =TCP_PORT;

SPI_Write(S0_MR,eth_protocol);

delay_ms(55);

// ======================== some server ip that replay
SPI_Write(S0_DIPR + 0,54.);
SPI_Write(S0_DIPR + 1,205);
SPI_Write(S0_DIPR + 2,230);
SPI_Write(S0_DIPR + 3,107);

//================================ set port 80 directly without any #define
SPI_Write(0x0410, 0x00 );
SPI_Write(0x0411, 0x50 );
delay_ms(10);

//======================================= open the socket 0
SPI_Write(S0_CR,CR_OPEN);
delay_ms(100);

//======================================================== save current ip to global variable
ip_tmp[0] = SPI_Read(SIPR + 0);
ip_tmp[1] = SPI_Read(SIPR + 1);
ip_tmp[2] = SPI_Read(SIPR + 2);
ip_tmp[3] = SPI_Read(SIPR + 3);

//============================================================ check if the ip is 0
if( (ip_tmp[0]==0) && (ip_tmp[1]==0) && (ip_tmp[2]==0) && (ip_tmp[3]==0) )
{
//if is 0.0.0.0 i set the subnet to 0.0.0.0
SPI_Write(SUBR + 0,0);
SPI_Write(SUBR + 1,0);
SPI_Write(SUBR + 2,0);
SPI_Write(SUBR + 3,0);
}

//=========================================================================== now try to connect
SPI_Write(S0_CR,CR_CONNECT);
delay_ms(300);

if (sock != 0) return retval;

if (SPI_Read(S0_SR) == SOCK_ESTABLISHED)
{
glcd_clear();
glcd_outtextxy(0,0, “socet connect”);
delay_ms(500);
}
else
if (SPI_Read(S0_SR) == SOCK_CLOSED)
{
glcd_clear();
glcd_outtextxy(0,0, “socet time out”);
delay_ms(500);
}
else
{
glcd_clear();
sprintf(lcd_buffer,"— S0_SR = %u \r\n" ,SPI_Read(S0_SR));
glcd_outtextxy(0,0, lcd_buffer);
sprintf(lcd_buffer,"— S0_IR = %u \r\n" ,SPI_Read(S0_IR));
glcd_outtextxy(0,10, lcd_buffer);

                                }

return subnet to 255.255.255.0
// Setting the Wiznet W5100 Sub Mask Address (SUBR): 0x0005 to 0x0008
SPI_Write(SUBR + 0,sub_mask[0]);
SPI_Write(SUBR + 1,sub_mask[1]);
SPI_Write(SUBR + 2,sub_mask[2]);
SPI_Write(SUBR + 3,sub_mask[3]);

return retval;
}
packet.zip (7.63 KB)

Hi,
before you have the ARP unanswered and now the ARP is gone and server will respond.
Now works locally? There still something else ?
The server gets a packet with 0 bytes of content and will respond with a packet with 0 bytes on port 0 of the W5100.


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