WIZ820io 서버 ip 설정 문제


#1

안녕하십니까.

현재 WIZ820io 을 이용하여 사용하고 있는데

나머지 Local IP 설정이나 Mac Address 설정 등 나머지 부분들은 다 설정이 되는데

Server IP 설정 하는 부분만 설정이 안되는 것 같아서 확인 요청 드립니다.
//
//
// 이슈사항
// Server IP를 Register에 Setting 후 다시 Read하여 확인결과 항상 0 으로 되어있음
//
// Register의 값을 Read하여 확인하는 부분은 이 Source의 가장 아랬부분에 있음.
//

#define SPI_CS PORTB.0
#define SCK PORTB.1
#define MOSI PORTB.2
#define MISO PORTB.3

//-----------------------------------------
// Server IP 설정
// 참고사항 : Register에 Setting되지 않음.
//-----------------------------------------
void SET_SERVER_IP()
{
unsigned int addr = 0x400C;

    SPI_CS = 0;
     
    //다음과 같이 Shift 연산자를 사용하지 않고 직접 값을 할당해도 마찬가지 결과가 나옴.
    //SPDR = 0x40;
    //while( !(SPSR & (1<<SPIF)) );
        
    //SPDR = 0x0C;
    //while( !(SPSR & (1<<SPIF)) );


    //주소 16 Bit --------------
    SPDR = ( (addr & 0xFF00) >> 8 );
    while( !(SPSR & (1<<SPIF)) );
        
    SPDR = (addr & 0x00FF);
    while( !(SPSR & (1<<SPIF)) );
        
    //OP-CODE + Length ----------
    SPDR = 0x80;
    while( !(SPSR & (1<<SPIF)) );
        
    SPDR = 0x04;
    while( !(SPSR & (1<<SPIF)) );
   
    //Data ---------------------      
    SPDR = 192;
    while( !(SPSR & (1<<SPIF)) ); 
     
    SPDR = 168;
    while( !(SPSR & (1<<SPIF)) );  
     
    SPDR = 0;
    while( !(SPSR & (1<<SPIF)) );  
     
    SPDR = 100;
    while( !(SPSR & (1<<SPIF)) );  
     
    SPI_CS = 1; 

}

//***************************************************************************
// 이하의 모든 Register 설정은 정상적으로 수행됨.
//***************************************************************************

//-----------------------------------------
// PORT DDR 설정
//-----------------------------------------
void Init_Port(void)
{
DDRB.3 = 0; //PB3(MISO)
DDRB.2 = 1; //PB2(MOSI);
DDRB.1 = 1; //PB1(SCK)
DDRB.0 = 1; //PB0(CS);
PORTB.0 = 1;
}

//-----------------------------------------
// Local IP 설정
//-----------------------------------------
void SET_CLIENT_IP()
{
SPI_CS = 0;

    //주소 16 Bit --------------
    SPDR = 0x00;
    while( !(SPSR & (1<<SPIF)) );
        
    SPDR = 0x0F; 
    while( !(SPSR & (1<<SPIF)) );
        
    //OP-CODE + Length ----------
    SPDR = 0x80;
    while( !(SPSR & (1<<SPIF)) );
        
    SPDR = 0x04;
    while( !(SPSR & (1<<SPIF)) );
   
    //Data ---------------------      
    SPDR = 192;
    while( !(SPSR & (1<<SPIF)) ); 
     
    SPDR = 168;
    while( !(SPSR & (1<<SPIF)) );  
     
    SPDR = 0;
    while( !(SPSR & (1<<SPIF)) );  
     
    SPDR = 50;
    while( !(SPSR & (1<<SPIF)) );  
     
    SPI_CS = 1; 

}

//-----------------------------------------
// Local Subnet mask 설정
//-----------------------------------------
void SET_CLIENT_SUBNET()
{

    SPI_CS = 0;
     
    //주소 16 Bit --------------
    SPDR = 0x00;
    while( !(SPSR & (1<<SPIF)) );
        
    SPDR = 0x05; 
    while( !(SPSR & (1<<SPIF)) );
        
    //OP-CODE + Length ----------
    SPDR = 0x80;
    while( !(SPSR & (1<<SPIF)) );
        
    SPDR = 0x4;
    while( !(SPSR & (1<<SPIF)) );
   
    //Data ---------------------      
    SPDR = 255;
    while( !(SPSR & (1<<SPIF)) ); 
     
    SPDR = 255;
    while( !(SPSR & (1<<SPIF)) );  
     
    SPDR = 255;
    while( !(SPSR & (1<<SPIF)) );  
     
    SPDR = 0;
    while( !(SPSR & (1<<SPIF)) );  
     
    SPI_CS = 1;      

}

//-----------------------------------------
// MAC ADDRESS 설정
//-----------------------------------------
void SET_CLIENT_MAC()
{
SPI_CS = 0;

    //주소 16 Bit --------------
    SPDR = 0x00;
    while( !(SPSR & (1<<SPIF)) );
        
    SPDR = 0x09; 
    while( !(SPSR & (1<<SPIF)) );
        
    //OP-CODE + Length ----------
    SPDR = 0x80;
    while( !(SPSR & (1<<SPIF)) );
        
    SPDR = 0x06;
    while( !(SPSR & (1<<SPIF)) );
   
    //Data ---------------------      
    SPDR = 0x01;
    while( !(SPSR & (1<<SPIF)) ); 
     
    SPDR = 0x02;
    while( !(SPSR & (1<<SPIF)) );  
     
    SPDR = 0x03;
    while( !(SPSR & (1<<SPIF)) );  
     
    SPDR = 0x04;
    while( !(SPSR & (1<<SPIF)) );  
     
    SPDR = 0x05;
    while( !(SPSR & (1<<SPIF)) );  
     
    SPDR = 0x06;
    while( !(SPSR & (1<<SPIF)) );  
     
    SPI_CS = 1;      

}

//-----------------------------------------
// GATEWAY 설정
//-----------------------------------------
void SET_CLIENT_GATEWAY()
{
SPI_CS = 0;

    //주소 16 Bit --------------
    SPDR = 0x00;
    while( !(SPSR & (1<<SPIF)) );
        
    SPDR = 0x01; 
    while( !(SPSR & (1<<SPIF)) );
        
    //OP-CODE + Length ----------
    SPDR = 0x80;
    while( !(SPSR & (1<<SPIF)) );
        
    SPDR = 0x04;
    while( !(SPSR & (1<<SPIF)) );
   
    //Data ---------------------      
    SPDR = 192;
    while( !(SPSR & (1<<SPIF)) ); 
     
    SPDR = 168;
    while( !(SPSR & (1<<SPIF)) );  
     
    SPDR = 0;
    while( !(SPSR & (1<<SPIF)) );  
     
    SPDR = 1;
    while( !(SPSR & (1<<SPIF)) );  
     
    SPI_CS = 1; 

}

//-----------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------
// Register에 설정된 값 확인하기
//-----------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------

//-----------------------------------------
// Local IP 확인
//-----------------------------------------
void GET_CLIENT_IP()
{
unsigned char ADDR[4];
unsigned char BUFF[50];
unsigned char i = 0;

SPI_CS = 0;

//주소 16 Bit --------------
SPDR = 0x00;
while( !(SPSR & (1<<SPIF)) );

SPDR = 0x0F; 
while( !(SPSR & (1<<SPIF)) );

//OP-CODE + Length ----------
SPDR = 0x00;
while( !(SPSR & (1<<SPIF)) );

SPDR = 0x04; 
while( !(SPSR & (1<<SPIF)) );

//Data Read -----------------
SPDR = 0x00;             
while( !(SPSR & (1<<SPIF)) );
ADDR[0] = SPDR;          

SPDR = 0x00;             
while( !(SPSR & (1<<SPIF)) );
ADDR[1] = SPDR;          

SPDR = 0x00;              
while( !(SPSR & (1<<SPIF)) );
ADDR[2] = SPDR;          

SPDR = 0x00;              
while( !(SPSR & (1<<SPIF)) );
ADDR[3] = SPDR;           

SPI_CS = 1;
  
delay_ms( 100 );
           
sprintf(BUFF,"%c  IP ADDRESS:%03d.%03d.%03d.%03d%c",2,ADDR[0],ADDR[1],ADDR[2],ADDR[3],3);

for(i=0; i<30; i++) putchar1( BUFF[i] );

}

//-----------------------------------------
// Server IP 확인
//-----------------------------------------
void GET_SERVER_IP()
{
unsigned int addr = 0x400C;
unsigned char ADDR[4];
unsigned char BUFF[50];
unsigned char i = 0;

SPI_CS = 0;

//주소 16 Bit --------------
SPDR = ( (addr & 0xFF00) >> 8 );
while( !(SPSR & (1<<SPIF)) );

SPDR = (addr & 0x00FF);
while( !(SPSR & (1<<SPIF)) );

//OP-CODE + Length ----------
SPDR = 0x00;
while( !(SPSR & (1<<SPIF)) );

SPDR = 0x04; 
while( !(SPSR & (1<<SPIF)) );

//Data Read -----------------
SPDR = 0x00;            
while( !(SPSR & (1<<SPIF)) );
ADDR[0] = SPDR;           

SPDR = 0x00;             
while( !(SPSR & (1<<SPIF)) );
ADDR[1] = SPDR;          

SPDR = 0x00;              
while( !(SPSR & (1<<SPIF)) );
ADDR[2] = SPDR;          

SPDR = 0x00;              
while( !(SPSR & (1<<SPIF)) );
ADDR[3] = SPDR;           

SPI_CS = 1;

delay_ms( 100 );
         
sprintf(BUFF,"%c   SERVER IP:%03d.%03d.%03d.%03d%c",2,ADDR[0],ADDR[1],ADDR[2],ADDR[3],3);

for(i=0; i<30; i++) putchar1( BUFF[i] );

}


#2

말씀하신 서버 아이피 주소 즉 Sn_DIPR는 Verify가 되는 Read/Write register가 아닙니다.
Write값과 Read 값이 다를 수 있습니다.
TCP 서버나 클라이언트로 동작할 경우 상대방이 접속했거나, 내가 접속을 성공 했을 때, Valid한 정보를 읽을 수 있습니다.
즉, 말씀하신 경우는 클라이언트로 동작하는 경우로 Sever IP를 기록하고 connect command를 수행하고, 그후 Sn_IR(CONNECT) bit가 '1’로 설정되거나 Sn_SR이 SOCK_ESTABLISHED 상태일때 읽어 보세요.


#3

또, 한가지

Sn_DIPR뿐 아니라, Sn_DHAR/Sn_DPORT 처럼 Destination관련하여 설정되는 register는 연결 후에 값이 변경됩니다.
참고하시기 바랍니다.

thanks, :slight_smile: