Unknown status when TCP client runs.

The client runs.
int32_t WIZNET_Run(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destport, uint16_t *rcv_size)
{
int32_t loc_ret, ret = 0; // return value for SOCK_ERRORs
uint16_t size = 0, sentsize=0;
static int first_send = 0;

     // Port number for TCP client (will be increased)
    static uint16_t any_port = 	50000;

    uint8_t status = wiz_getSn_SR(sn);

   switch(status)
   {
        case SOCK_ESTABLISHED :
            if(status & Sn_IR_CON)	
            {
	    wiz_setSn_IR(sn, Sn_IR_CON);  

	    if((size = getSn_RX_RSR(sn)) > 0) 
               {
		if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE; /
		loc_ret = wiz_recv(sn, buf, size); 
		if(loc_ret <= 0) 
		    	 return STAT_RX_FAILED; 
		 size = (uint16_t) loc_ret;
		    
		*rcv_size = size;
         }
	    
	 ret = STAT_SOCK_OK;
     break;

     case SOCK_CLOSE_WAIT :
         loc_ret = wiz_disconnect(sn);
         if(loc_ret != SOCK_OK) 
        
         ret = STAT_SOCK_NOT_OK;
     break;

     case SOCK_INIT :
         loc_ret = wiz_connect(sn, destip, destport);
	     if( loc_ret != SOCK_OK) 
	    	 ret = STAT_SOCK_NOT_OK;
     break;

     case SOCK_CLOSED:
         wiz_close(sn);
    	 
         ret = wiz_socket(sn, Sn_MR_TCP, any_port++, 0x00);
	     if(ret != sn)
	     {
             if(any_port == 0xffff) 
            	 any_port = 50000;
             
             ret = STAT_SOCK_NOT_OK; // TCP socket open with 'any_port' port number
         } 
	     
        //set auto keep alive every 5 sec
        setSn_KPALVTR(sn, 1); 
     break;
     
     default:
     break;

}
return ret;
}

I get SOCK_ESTABLISHED and it runs OK.
wiznet_status = WIZNET_Run(SOCK_TCPS, read_buf, tcp_server_ip, PORT_TCPS, &TCP_RecSize);

But if I send something
if (wiznet_status == STAT_SOCK_OK)
{
if (wiz_send(SOCK_TCPS, messages_Q_Buffer, Q_RecvSize) == ERROR)
{
printf(“Error Sending Message\n”);
}

I get in uint8_t status = wiz_getSn_SR(sn); - status = 0x03 and it is invalid status – there are no such documented status.

Most probably you supply some wrong argument to the sending routine, or there’s some memory overlap and application writes to the unintended locations (in wrong registers).

It is hard to suggest anything as there’s no tech data available on the issue, but I hope you have got a direction to research into.

But why status gets an invalid value - 0x03? It stays this way till I reset.

It is impossible that the value of Sn_SR register becomes 0x03.
Sn_SR can’t have undefined value in datasheet.

So, I think so this problem is another issue.
As eugeny sadi, plz check to your system in another point view.

Thank you.

1 Like