WIZ811MJ Not Working

#1

I need help with this module.
Im interfacing it with an AVR ATMega2560, and i cant make it work.

Im trying to initilize it but there is no response, there are my init functions:

void SPI_Init(void)
{
// Initial the AVR ATMega SPI Peripheral
// Set MOSI and SCK as output
DDRB = (1<<PINB2)|(1<<PINB1)|(1<<PINB0);
// Set MISO as input
//DDRB &= ~(1<<PINB3);

//Pull high W5100_CS and set W5100_CS as output
//DDRB |= (1<<PINB0);
PORTB |= (1<<PINB0);

// Enable SPI, Master Mode 0, set the clock rate fck/8
SPCR = (1<<SPE)|(1<<MSTR);
SPCR &= ~(1<<CPHA);
SPCR &= ~(1<<CPOL);
SPSR |= (1<<SPI2X);

}

void SPI_Write(unsigned int addr,unsigned char data)
{
// Activate the CS pin
PORTB &= ~(1<<PINB0);
// Start W5100 Write OpCode transmission
SPDR = WIZNET_WRITE_OPCODE;
// Wait for transmission complete
while(!(SPSR & (1<<SPIF)));
// Start W5100 Address High Bytes transmission
SPDR = (addr & 0xFF00) >> 8;
// Wait for transmission complete
while(!(SPSR & (1<<SPIF)));
// Start W5100 Address Low Bytes transmission
SPDR = addr & 0x00FF;
// Wait for transmission complete
while(!(SPSR & (1<<SPIF)));

// Start Data transmission
SPDR = data;
// Wait for transmission complete
while(!(SPSR & (1<<SPIF)));
// CS pin is not active
PORTB |= (1<<PINB0);

}

unsigned char SPI_Read(unsigned int addr)
{
// Activate the CS pin
PORTB &= ~(1<<PINB0);
// Start W5100 Read OpCode transmission
SPDR = WIZNET_READ_OPCODE;
// Wait for transmission complete
while(!(SPSR & (1<<SPIF)));
// Start W5100 Address High Bytes transmission
SPDR = (addr & 0xFF00) >> 8;
// Wait for transmission complete
while(!(SPSR & (1<<SPIF)));
// Start W5100 Address Low Bytes transmission
SPDR = addr & 0x00FF;
// Wait for transmission complete
while(!(SPSR & (1<<SPIF)));

// Send Dummy transmission for reading the data
SPDR = 0x00;
// Wait for transmission complete
while(!(SPSR & (1<<SPIF)));

// CS pin is not active
PORTB |= (1<<PINB0);
return(SPDR);

}

void W5100_Init(void)
{
printf(“Initializing W5100…\n\n”);

// Doing Hardware Reset
//DDRB |= (1<<PINB4);
//PORTB |= (1<<PINB4);

//PORTB &= ~(1<<PINB4);
//_delay_ms(5);
//PORTB |= (1<<PINB4);
//_delay_ms(10);

// Setting the W5100 Mode Register: 0x0000
// MR = 0b10000000;
SPI_Write(MR,0x80);
_delay_ms(1);
printf("Reading MR: %d\n\n",SPI_Read(MR));

printf("W5100 Initialized!\n");

}

void W5100_Config(void)
{
W5100_Init();
printf(“configuring W5100…\n\n”);

// Setting the W5100 Gateway Address (GAR): 0x0001 to 0x0004
printf("Setting Gateway Address %d.%d.%d.%d\n",Setup_Gateway[0],Setup_Gateway[1],Setup_Gateway[2],Setup_Gateway[3]);
SPI_Write(GAR + 0,Setup_Gateway[0]);
SPI_Write(GAR + 1,Setup_Gateway[1]);
SPI_Write(GAR + 2,Setup_Gateway[2]);
SPI_Write(GAR + 3,Setup_Gateway[3]);
_delay_ms(1);
printf("Reading GAR: %d.%d.%d.%d\n\n",SPI_Read(GAR + 0),SPI_Read(GAR + 1),SPI_Read(GAR + 2),SPI_Read(GAR + 3));

// Setting the W5100 Source Address Register (SAR): 0x0009 to 0x000E
printf("Setting Source Address %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",Setup_MAC[0],Setup_MAC[1],Setup_MAC[2],Setup_MAC[3],Setup_MAC[4],Setup_MAC[5]);
SPI_Write(SAR + 0,Setup_MAC[0]);
SPI_Write(SAR + 1,Setup_MAC[1]);
SPI_Write(SAR + 2,Setup_MAC[2]);
SPI_Write(SAR + 3,Setup_MAC[3]);
SPI_Write(SAR + 4,Setup_MAC[4]);
SPI_Write(SAR + 5,Setup_MAC[5]);
_delay_ms(1);
printf("Reading SAR: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n\n",SPI_Read(SAR + 0),SPI_Read(SAR + 1),SPI_Read(SAR + 2),SPI_Read(SAR + 3),SPI_Read(SAR + 4),SPI_Read(SAR + 5));

// Setting the W5100 Sub Mask Address (SUBR): 0x0005 to 0x0008
printf("Setting Sub Mask Address %d.%d.%d.%d\n",Setup_DNSMASK[0],Setup_DNSMASK[1],Setup_DNSMASK[2],Setup_DNSMASK[3]);
SPI_Write(SUBR + 0,Setup_DNSMASK[0]);
SPI_Write(SUBR + 1,Setup_DNSMASK[1]);
SPI_Write(SUBR + 2,Setup_DNSMASK[2]);
SPI_Write(SUBR + 3,Setup_DNSMASK[3]);
_delay_ms(1);
printf("Reading SUBR: %d.%d.%d.%d\n\n",SPI_Read(SUBR + 0),SPI_Read(SUBR + 1),SPI_Read(SUBR + 2),SPI_Read(SUBR + 3));

// Setting the W5100 IP Address (SIPR): 0x000F to 0x0012
printf("Setting IP Address %d.%d.%d.%d\n",Setup_IP[0],Setup_IP[1],Setup_IP[2],Setup_IP[3]);
SPI_Write(SIPR + 0,Setup_IP[0]);
SPI_Write(SIPR + 1,Setup_IP[1]);
SPI_Write(SIPR + 2,Setup_IP[2]);
SPI_Write(SIPR + 3,Setup_IP[3]);
_delay_ms(1);
printf("Reading SIPR: %d.%d.%d.%d\n\n",SPI_Read(SIPR + 0),SPI_Read(SIPR + 1),SPI_Read(SIPR + 2),SPI_Read(SIPR + 3));

// Setting the W5100 RX and TX Memory Size, we use 2KB for Rx/Tx 4 channels
printf("Setting W5100 RMSR and TMSR\n\n");
SPI_Write(RMSR,0x55);
SPI_Write(TMSR,0x55);
printf("W5100 Configured!\n");

}

Im using this code from a web blog, but dont work for me and i dont know where is the problem.
I have analized de SPI bus and for me all was ok, i can send a capture of the bus.

Help please!!!

Thanks

#2

Hi,
I found dummy read at another AVR SPI example.

Like As following code, modify it and test again.

void SPI_Write(unsigned int addr,unsigned char data)
{
        char dummy;
	// Activate the CS pin
	PORTB &= ~(1<<PINB0);
	// Start W5100 Write OpCode transmission
	SPDR = WIZNET_WRITE_OPCODE;
	// Wait for transmission complete
	while(!(SPSR & (1<<SPIF)));
        temp = SPDR;                      //<-- Just for clearing SPIF flag.

	// Start W5100 Address High Bytes transmission
	SPDR = (addr & 0xFF00) >> 8;
	// Wait for transmission complete
	while(!(SPSR & (1<<SPIF)));
        temp = SPDR;                      //<-- Just for clearing SPIF flag.

	// Start W5100 Address Low Bytes transmission
	SPDR = addr & 0x00FF;
	// Wait for transmission complete
	while(!(SPSR & (1<<SPIF)));
        temp = SPDR;                      //<-- Just for clearing SPIF flag.

	// Start Data transmission
	SPDR = data;
	// Wait for transmission complete
	while(!(SPSR & (1<<SPIF)));
        temp = SPDR;                      //<-- Just for clearing SPIF flag.

	// CS pin is not active
	PORTB |= (1<<PINB0);
}

If the test result is same, post the capture SPI signals on here.
Thank you.

#3

After your adding your modification, im having back response from the wiz811 module, but there is somothing wrong, i can’t setup properly the GWR,SUBR,SHAR and SIPR registers.
Here s a screenshoot of my logic analyzer.






#4

More screenshoots…






#5

Hi,
I was checked the captured SPI signal, But It seems to be likely to be wrong.
In W5100 SPI Write register, MISO signal outputs 0x00, 0x01, 0x02, 0x03 as shown ‘MR Writing For reset.png’.
In W5100 SPI Read register, MISO signal outputs 0x00, 0x01, 0x02, DATA as shown ‘MR Reading after reset.png’.

But In GAR,SUBR, SIPR and SHAR Writing figures, They have some problem.
I attachted the result of analyzation. The yellow box is correct and The blue box is not correct.


MOSI signal is all correct. But, 2nd & 3rd MISO signal is not correct.


MOSI signal is all correct. But, 4th MISO signal is not correct.


MOSI signal is not corret at 2nd address of SUBR. MOSI signal is 0x0003 but it maybe 0x0006.
And 1st & 2nd MISO signal is not correct.

#6


MOSI signal is not correct at 5th address of SHAR. MOSI is 0x0006 but it maybe 0x000D.
And 2nd, 3th & 5th MISO signal is not correct.

Most of All, Why MOSI signal broken to writing the address of W5100 REGs?

I checked the related SPI of ATmega2560. So, No need to read dummy SPDR after writing SPDR because SPDR have always the latest value.

First, You should be read RCR and RTR. RCR & RTR have 0x08 & 0x07D0 respectively, after they reset.
And add the delay after SCS control.

void SPI_Write(unsigned int addr,unsigned char data)
{
	// Activate the CS pin
	PORTB &= ~(1<<PINB0);
        _delay_ms(1);  //<<-- add to the delay

	// Start W5100 Write OpCode transmission
	SPDR = WIZNET_WRITE_OPCODE;
	// Wait for transmission complete
	while(!(SPSR & (1<<SPIF)));
	// Start W5100 Address High Bytes transmission
	SPDR = (addr & 0xFF00) >> 8;
	// Wait for transmission complete
	while(!(SPSR & (1<<SPIF)));
	// Start W5100 Address Low Bytes transmission
	SPDR = addr & 0x00FF;
	// Wait for transmission complete
	while(!(SPSR & (1<<SPIF)));

	// Start Data transmission
	SPDR = data;
	// Wait for transmission complete
	while(!(SPSR & (1<<SPIF)));
	// CS pin is not active
	PORTB |= (1<<PINB0);
       _delay_ms(1);       //<<-- add to the delay
}

unsigned char SPI_Read(unsigned int addr)
{
	// Activate the CS pin
	PORTB &= ~(1<<PINB0);
      _delay_ms(1);       //<<-- add to the delay

	// Start W5100 Read OpCode transmission
	SPDR = WIZNET_READ_OPCODE;
	// Wait for transmission complete
	while(!(SPSR & (1<<SPIF)));
	// Start W5100 Address High Bytes transmission
	SPDR = (addr & 0xFF00) >> 8;
	// Wait for transmission complete
	while(!(SPSR & (1<<SPIF)));
	// Start W5100 Address Low Bytes transmission
	SPDR = addr & 0x00FF;
	// Wait for transmission complete
	while(!(SPSR & (1<<SPIF)));

	// Send Dummy transmission for reading the data
	SPDR = 0x00;
	// Wait for transmission complete
	while(!(SPSR & (1<<SPIF)));

	// CS pin is not active
	PORTB |= (1<<PINB0);
      _delay_ms(1);       //<<-- add to the delay

	return(SPDR);
}

Remember that MISO signal always outputs 0x00, 0x01, 0x02, and 0x03 (Write) / DATA(Read).

#7

There is a problem in my /RESET line, and in the logical level of MISO,MOSI,SS,SCK.

For the issue with the /RESET line i have put a 10k resistor, and for the logical level issue, y made a logical converter 3V3 to 5v ,5V to 3V3 with four 2N7000 and a few resistors.
In the Wiz5100 Datasheet says that the IC is 5V tolerant, but in my case doesn’t work without adapt the levels.

Now all is working ok for me.

Thanks for your replies!!!

#8

Hi,
I wonder why W5100 can’t tolerate with 5V IO in your system.

BTW, I’m glad to solve your problem.

Thank you.