WIZnet Developer Forum

Problem in programming

hi
i have some problems with w5100 when i want to program it.
1.when i write in Gateway_IP register, after that i cant see the content of it. but when i use an infinite loop for writing and reading the register it works and I see the content . so have you ever had this problem? is it normal or my programming isn’t correct ?
2. i have written in below registers for Ping command is it enough or i have to wrote in other registers ?

  • Gateway Address Register
  • Source Hardware Address Register
  • Subnet Mask Register
  • Source IP Address Register
  • Interrupt Mask Register
  • Set up RX Memory Size Register and TX Memory Size Register
  • Initialize W5100 with S/W reset.

thanks

You need to give background: when you write, what you write, what hardware platform you use.
It is not correct that you can not read GAR back, but it may happen because you do something in wrong time.

[quote=“kavireloot”]2. i have written in below registers for Ping command is it enough or i have to wrote in other registers ?

  • Gateway Address Register
  • Source Hardware Address Register
  • Subnet Mask Register
  • Source IP Address Register
  • Interrupt Mask Register
  • Set up RX Memory Size Register and TX Memory Size Register
  • Initialize W5100 with S/W reset.[/quote]
    This is wrong.

should be the first step, not the last. When you perform reset on the chip all settings you set before are cleared. You also should ensure you set PB bit in MR register for ping to work.

Thanks for your attention.
My mcu is STM32f103xx
This is my code :

void W5100_Init(void)
{
unsigned char i;
Write_W5100(W5100_MODE,MODE_RST);
for(i=0;i<6;i++)
  Write_W5100(W5100_SHAR+i,Phy_Addr[i]);
 for(i=0;i<4;i++)
  Write_W5100(W5100_GAR+i,Gateway_IP[i]); 
for(i=0;i<4;i++)
  Write_W5100(W5100_SUBR+i,Sub_Mask[i]);
for(i=0;i<4;i++)
  Write_W5100(W5100_SIPR+i,IP_Addr[i]);
Write_W5100(W5100_IMR,0xc3);   
Write_W5100(W5100_RMSR,0xAA);					        	
Write_W5100(W5100_TMSR,0xAA);						      
Write_W5100(W5100_RTR,0x07);
Write_W5100(W5100_RTR+1,0xD0);
Write_W5100(W5100_RCR,8);
}

int main()
{
W5100_Init();
while(1);
}

Is it wrong?

Logically it is correct. How do you define constants and arrays?
W5100_MODE=?
MODE_RST=?
W5100_SHAR=?
Phy_Addr=?
W5100_GAR=?
Gateway_IP=?
W5100_SUBR=?
Sub_Mask=?
W5100_SIPR=?
IP_Addr=?
W5100_IMR=?
W5100_RMSR=?
W5100_TMSR=?
W5100_RTR=?
W5100_RTR=?
W5100_RCR=?

What is the code of Write_W5100()?
Where failure in this code occurs giving you unexpected result, what is wrong result and what is expected result?

#define COMMON_BASE	                                0x0000
#define W5100_MODE	                                COMMON_BASE
#define MODE_RST		                                0x80		
#define W5100_SHAR	                                        COMMON_BASE+0x09
unsigned char Phy_Addr[6]={0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
#define W5100_GAR                                 	        COMMON_BASE+0x01
unsigned char Gateway_IP[4]={192,168,1,38};
#define W5100_SUBR	                                        COMMON_BASE+0x05
unsigned char Sub_Mask[4]={255,255,255,0};
#define W5100_SIPR	                                        COMMON_BASE+0x0f
unsigned char IP_Addr[4]={192,168,1,1};
#define W5100_IMR                                   	COMMON_BASE+0x16
#define W5100_RMSR	                                COMMON_BASE+0x1a
#define W5100_TMSR	                                COMMON_BASE+0x1b
#define W5100_RTR	                                        COMMON_BASE+0x17
#define W5100_RCR	                                        COMMON_BASE+0X19



#define W5100_SCS_LOW 	                        GPIO_ResetBits(GPIOB,GPIO_Pin_0)		
#define W5100_SCS_HIGH                        	GPIO_SetBits(GPIOB,GPIO_Pin_0)



unsigned char SPI_SendByte(unsigned char dt) // unsigned char 8 bit
{ 

	while((SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_TXE) == RESET)); 

	SPI_I2S_SendData(SPI2,dt); 

	while((SPI_I2S_GetFlagStatus(SPI2,SPI_I2S_FLAG_RXNE) == RESET));
	return SPI_I2S_ReceiveData(SPI2); 
}

void Write_W5100(unsigned int Addr,unsigned char byte) 
{ 
 	W5100_SCS_LOW;	 
	  
	SPI_SendByte(0xf0); 

	SPI_SendByte((Addr & 0xFF00) >> 8); 
	SPI_SendByte(Addr & 0x00FF); 

	SPI_SendByte(byte); 

  W5100_SCS_HIGH;	
} 

For example:
when i write 0xaa in RMSR register i can read it (0xaa)
but when i write 192 in W5100_GAR register i cant read it and i receive 0…

[quote=“kavireloot”]unsigned char Phy_Addr[6]={0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
[/quote]
Try different one:

Is the other code correct?

Well, I do not see SPI clock in the code, thus it is not possible to check if SPI communication is correct. However as you say you get AA back, we assume SPI protocol works. There’s one issue though. You write 80 into mode register, signalling W5100 to reset, but do not wait for its reset completion. Before doing anything else you should ensure that bit 7 is 0 = reset complete.

hi
thanks for your helping.
i have done the ping command and its works well.

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