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)