Data Sheet
© Copyright 2013 WIZnet Co.,Ltd. All rights reserved. 
48
iEthernet 
W5200
{ 
START: 
Sn_MR = 0x01;    // sets TCP mode   
Sn_PORT0 = source_port;                // sets source port number 
Sn_CR = OPEN;      // sets OPEN command   
/* wait until Sn_SR is changed to SOCK_INIT */ 
if (Sn_SR != SOCK_INIT) Sn_CR = CLOSE; goto START; 
} 
LISTEN 
Run as “TCP SERVER” by LISTEN command. 
{ 
/* listen SOCKET */ 
Sn_CR = LISTEN; 
/* wait until    Sn_SR is changed to SOCK_LISTEN */ 
if (Sn_SR != SOCK_LISTEN) Sn_CR = CLOSE; goto START; 
} 
ESTABLISHMENT 
When  the  status  of  Sn_SR  is  SOCK_LISTEN,  if  it  receives  a  SYN  packet,  the  status  of 
Sn_SR is changed to SOCK_SYNRECV and transmits the SYN/ACK packet. After that, the 
Socket n    makes a connection. After it makes the connection of Socket n , it enables 
the data communication. There are two methods to confirm the connection of Socket 
n . 
First method : 
{ 
if (Sn_IR(CON) == ‘1’)   
/* When an interrupt occurs and the mask bit of Sn_IMR is ‘1’, the interrupt bit of Sn_IR 
becomes ‘1’ */     
Sn_IR(CON) = ‘1’;   
  /*In order to clear the Sn_IR bit, the host should write the bit as ‘1’. When all the bits of 
Sn_IR is cleared (‘0’), IR(n) is automatically cleared.*/ 
goto ESTABLISHED stage; 
/* In this case, if the interrupt of Socket n    is activated, interrupt occurs. Refer to IR, IMR 
Sn_IMR and Sn_IR. */ 
} 
Second method : 
{ 
if (Sn_SR == SOCK_ESTABLISHED) goto ESTABLISHED stage; 
} 










