Spi to ethernet communication.

Hello,

We are using the W5500 chip for the spi to Ethernet communication in our project. And i have some doubts regarding the programming of the chip.
Do the chip (w5500) requires additional programming? or the spi frame send from the master configures the whole process of the chip?

For getting the spi data through the ethernet what all configurations are required? can you explain the basic configurations required with a pseudo code or a flow chart?

And whats is the default spi baud rate of the W5500 EVB? if to be changed how can i change the baud rate.

Please don’t reply with the library file link on github.

First, please let me know what use our product name you use.
For example, just use W5500 Chip or use W5500 EVB

If you use the W5500 EVB , you just compile the project that we support project via github and download the firmware.
If you configure the board with W5500, you must send the data as SPI frame of W5500 from MCU.

hello irina ,
thanks for the reply.
Right now i have the W5500 EVB and AOKIN ethernet network module with me .
my only aim is to get the spi data(From another MCU (tms320f28335)) over the ethernet, and monitor it through wire shark.

The W5500’s SPI supports 80 MHz speed
What Ethernet communication do you want?
First, you should connect SPI with MCU.
And set the Source Network information .

Also set the socket communication.
please refer to 4.3.1, 4.3.2 and 4.4.1 of W5100S data sheet.

correct me if i am wrong, as per what i undrstood from the data sheet to establish the spi communication and get the data over the ethernet we need to send the data as per the spi frame of the W5500. And this frame is what configures the w5500 .

so that should be like this right?

first send the frame with the control bit and address phase selecting the Common register and set the ip mac and stuff there.

secondly, send other frame with address phase and control phase selecting socket register for protocol slection and all??
is that the way???

If you have W5500 EVB, did you execute the examples code?
and did you succeed for example code?
what’s the example code you execute?

did you configure SPI?
did you initialize w5500?
EX)
void SPI_Init()
{

/* SSP initialization */
Init_SSP_PinMux();
Chip_SSP_Init(LPC_SSP0);

Chip_SSP_SetFormat(LPC_SSP0, SSP_BITS_8, SSP_FRAMEFORMAT_SPI, SSP_CLOCK_MODE0);
Chip_SSP_SetMaster(LPC_SSP0, true);
Chip_SSP_SetBitRate(LPC_SSP0, 10000000); // 10MHz
Chip_SSP_Enable(LPC_SSP0);

}

void W5500_Init()
{

uint8_t tmp;
uint8_t memsize[2][8] = { { 2, 2, 2, 2, 2, 2, 2, 2 }, { 2, 2, 2, 2, 2, 2, 2, 2 } };

Chip_GPIO_SetPinState(LPC_GPIO, 0, 2, true);	// SSEL(CS)

Chip_GPIO_SetPinState(LPC_GPIO, 0, 22, false);	// N_RESET
tmp = 0xFF;
while(tmp--);
Chip_GPIO_SetPinState(LPC_GPIO, 0, 22, true);	// N_RESET

reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect);
reg_wizchip_spi_cbfunc(wizchip_read, wizchip_write);

/* wizchip initialize*/
if (ctlwizchip(CW_INIT_WIZCHIP, (void*) memsize) == -1) {
	printf("WIZCHIP Initialized fail.\r\n");
	while (1);
}

}

If you succeed SPI initialize or W5500 initialize, you will read VERSIONR resister.
what is VERSIONR resister value?
VERSIONR resister value must be 0x04.


image

Hello

Thanks becky,
let me try it out.
Can u please tell what baud rate should i use?
You said 80Mhz right? How much bits per second is 80MHz?

Could you please answer me about above question?
80Mhz means SPI Clock that it send from SPI master.
Therefore, it is different with SPI baud rate and it is just SPI clock speed.

For example,
For reading the version register in W5500, it need the 32bits.
Assuming no delay between bit, the calculation is as follows.
`1/80MHz 32bits = 12.5ns32 =400ns

Even though theoretical design speed is 80MHz, the signal in the high speed may be distorted because of the circuit crosstalk and the length of the signal line. The minimum guaranteed speed of the SCLK is 33.3 MHz which was tested and measured with the stable waveform.
Please refer to the SPI Application Note which shows the WIZnet test environment and results.

this is the code i wrote for the spi communication from tms320f28335 to w5500 spi to ethernet module.
please check if the code is correct and correct me if i am wrong .

if am wrong please help me with a pseudo code for the same

//###########################################################################

#include “DSP28x_Project.h” // Device Headerfile and Examples Include File

// Prototype statements for functions found within this file.
// __interrupt void ISRTimer2(void);
typedef unsigned char uint8;
void delay_loop(void);
void spi_xmit(uint8 a);
void spi_fifo_init(void);
void spi_init(void);
void error(void);
void netwrkconfig(void);
void socketinit(void);
void portnum(void);
void opencmd(void);
void listencmd(void);
void txdata(void);
void sendcmd(void);
uint8 sdata;

void main(void)
{
// send data
//Uint16 rdata; // received data

// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks

InitSysCtrl();

// Step 2. Initialize GPIO:
//
InitSpiaGpio();

// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;

// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.
InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;

// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
InitPieVectTable();

// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c

spi_fifo_init(); // Initialize the Spi FIFO
spi_init(); // init SPI

// Step 5. User specific code:
// Interrupts are not used in this example.

for(;:wink:
{
// Transmit data

 GpioDataRegs.GPBCLEAR.bit.GPIO57 =1; // SCS asserted low for data transmission
 netwrkconfig();
 GpioDataRegs.GPBSET.bit.GPIO57 = 1;  // SCS asserted high to inidcate end of the frame.

 GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1;
 socketinit();
 GpioDataRegs.GPBSET.bit.GPIO57 = 1;

 GpioDataRegs.GPBCLEAR.bit.GPIO57 =1;
 portnum();
 GpioDataRegs.GPBSET.bit.GPIO57 = 1;

 GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1;
 opencmd();
 GpioDataRegs.GPBSET.bit.GPIO57 = 1;

 GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1;
 listencmd ();
 GpioDataRegs.GPBSET.bit.GPIO57 = 1;

 GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1;
 txdata ();
 GpioDataRegs.GPBSET.bit.GPIO57 = 1;

 GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1;
 sendcmd ();
 GpioDataRegs.GPBSET.bit.GPIO57 = 1;

 // Wait until data is received
 //while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) { }
 // Check against sent data
 //rdata = SpiaRegs.SPIRXBUF;
 //if(rdata != sdata) error();

}
}
// spi frame data functions:
//*********************************************************************************

void netwrkconfig()
{
//ip address mac SUBR SHAR SIPR are set here

 sdata = 0x00;
 spi_xmit(sdata);

 sdata = 0x00;
 spi_xmit(sdata);

 sdata = 0x01;
 spi_xmit(sdata);

 sdata = 0x04;
 spi_xmit(sdata);

 sdata = 0xC0;
 spi_xmit(sdata);

 sdata = 0xA8;
 spi_xmit(sdata);

 sdata = 0x00;
 spi_xmit(sdata);

 sdata = 0x01;
 spi_xmit(sdata);

 sdata = 0xFF;
 spi_xmit(sdata);

 sdata = 0xFF;
 spi_xmit(sdata);

 sdata = 0xFF;
 spi_xmit(sdata);


 sdata = 0x00;
 spi_xmit(sdata);

 sdata = 0x00;
 spi_xmit(sdata);

 sdata = 0x08;
 spi_xmit(sdata);

 sdata = 0xDC;
 spi_xmit(sdata);

 sdata = 0x01;
 spi_xmit(sdata);

 sdata = 0x02;
 spi_xmit(sdata);

 sdata = 0x03;
 spi_xmit(sdata);

 sdata = 0xC0;
 spi_xmit(sdata);

 sdata = 0xA8;
 spi_xmit(sdata);

 sdata = 0x00;
 spi_xmit(sdata);

 sdata = 0x02;
 spi_xmit(sdata);

}

//===========================================================================
// *****************************************
void socketinit()
{
// Sn3_MR reg
sdata = 0x0;
spi_xmit(sdata);

	sdata = 0x0;
	spi_xmit(sdata);

	sdata = 0x04;
	spi_xmit(sdata);

	sdata = 0x01;
	spi_xmit(sdata);

}

void portnum()
{
//Sn_PORT
sdata = 0x00;
spi_xmit(sdata);

	sdata = 0x04;
	spi_xmit(sdata);

	sdata = 0x0C;
	spi_xmit(sdata);

	sdata = 0x13;
	spi_xmit(sdata);

	sdata = 0x88;
	spi_xmit(sdata);

}

void opencmd()
{
//Sn_CR reg
sdata = 0x00;
spi_xmit(sdata);

	sdata = 0x01;
	spi_xmit(sdata);

	sdata = 0x0C;
	spi_xmit(sdata);

	sdata = 0x01;
	spi_xmit(sdata);

}

void listencmd ()
{
//Sn_CR
sdata = 0x00;
spi_xmit(sdata);

	sdata = 0x01;
	spi_xmit(sdata);

	sdata = 0x0C;
	spi_xmit(sdata);

	sdata = 0x02;
	spi_xmit(sdata);

}

//*******************************************************
void txdata ()
{
sdata = 0x00;
spi_xmit(sdata);

	sdata = 0x00;
	spi_xmit(sdata);

	sdata = 0x14;
	spi_xmit(sdata);

	sdata = 0xAA;
	spi_xmit(sdata);

	sdata = 0xAA;
	spi_xmit(sdata);

}

//*****************************************************

void sendcmd()
{
sdata = 0x00;
spi_xmit(sdata);

sdata = 0x01;
spi_xmit(sdata);

sdata = 0x0C;
spi_xmit(sdata);

sdata = 0x20;
spi_xmit(sdata);

}

// Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here:

void delay_loop()
{
long i;
for (i = 0; i < 1000000; i++) {}
}

void error(void)
{
__asm(" ESTOP0"); // Test failed!! Stop!
for (;;);
}

void spi_init()
{
SpiaRegs.SPICCR.all =0x000F; // Reset on, rising edge, 16-bit char bits
SpiaRegs.SPICTL.all =0x0006; // Enable master mode, normal phase,
// enable talk, and SPI int disabled.
SpiaRegs.SPIBRR =0x007F;
SpiaRegs.SPICCR.all =0x009F; // Relinquish SPI from Reset
SpiaRegs.SPIPRI.bit.FREE = 1; // Set so breakpoints don’t disturb xmission
}

void spi_xmit(uint8 a)
{
SpiaRegs.SPITXBUF=a;
}

void spi_fifo_init()
{
// Initialize SPI FIFO registers
SpiaRegs.SPIFFTX.all=0xE040;
SpiaRegs.SPIFFRX.all=0x204f;
SpiaRegs.SPIFFCT.all=0x0;
}

//===========================================================================
// No more.
//===========================================================================

hello

Why you didn’t use iolibrary for WIZNET?
why config and init functions are in the loop?
You didn’t initialize W5500.

you write wizchip_select() for CS set and reset functions.
and you write wizchip_read(), wizchip_write for SPI read& write data functions.

please, check this code.

thank you

Hello,
Am using the Ti’s tms320f28335 as Master . and i think no such library are available for that. If so there must a way to init and configure the w5500 right??

I think this data is 192.168.0.2 as SIPR, is it right?
If yes,where is the address of SIPR in code?
Also the ioLibrary isn’t dependent on the MCU and I don’t think you have any problem.
If you can’t use the ioLibrary, MCU should send data to W5500 SPI frame.
image
Further details refer to datasheet : W5500 Datasheet

as the address is auto incremented for each data , i gave only the starting address of GAR. (my mistake ). as of now i changed that.
and made some more modifications in the code.
I’ll post code below please check if any changes is required.

void main(void)
{
// send data
//Uint16 rdata; // received data

// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks

InitSysCtrl();

// Step 2. Initialize GPIO:
//
InitSpiaGpio();

// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;

// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.
InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;

// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
InitPieVectTable();

// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c

spi_fifo_init(); // Initialize the Spi FIFO
spi_init(); // init SPI

// Step 5. User specific code:
// Interrupts are not used in this example.

for(;:wink:
{
// Transmit data
GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1;
MR_reg ();
GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1;

 GpioDataRegs.GPBCLEAR.bit.GPIO57 =1; // SCS asserted low for data transmission
 GAR();
 GpioDataRegs.GPBSET.bit.GPIO57 = 1;  // SCS asserted high to inidcate end of the frame.

 GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1;
 SUBR();
 GpioDataRegs.GPBSET.bit.GPIO57 = 1;

 GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1;
 SHAR();
 GpioDataRegs.GPBSET.bit.GPIO57 = 1;

 GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1;
 SIPR();
 GpioDataRegs.GPBSET.bit.GPIO57 = 1;

 GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1;
 Sn_MR();
 GpioDataRegs.GPBSET.bit.GPIO57 = 1;

 GpioDataRegs.GPBCLEAR.bit.GPIO57 =1;
 Sn_PORT();
 GpioDataRegs.GPBSET.bit.GPIO57 = 1;

 GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1;
 opencmd();
 GpioDataRegs.GPBSET.bit.GPIO57 = 1;

 GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1;
 Sn_DIPR();
 GpioDataRegs.GPBSET.bit.GPIO57 = 1;

 GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1;
 Sn_DPORT();
 GpioDataRegs.GPBSET.bit.GPIO57 = 1;

 GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1;
 listencmd ();
 GpioDataRegs.GPBSET.bit.GPIO57 = 1;

 GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1;
 txdata ();
 GpioDataRegs.GPBSET.bit.GPIO57 = 1;

 GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1;
 sendcmd ();
 GpioDataRegs.GPBSET.bit.GPIO57 = 1;

 // Wait until data is received
 //while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) { }
 // Check against sent data
 //rdata = SpiaRegs.SPIRXBUF;
 //if(rdata != sdata) error();

 asm ("	NOP");

}
}
// spi frame data functions:
//*********************************************************************************
void MR_reg ()
{
sdata = 0x00;
spi_xmit(sdata);

sdata = 0x00;
spi_xmit(sdata);

sdata =0x04;
spi_xmit(sdata);

sdata = 0x10;
spi_xmit(sdata);

}
void GAR()
{
//ip address mac SUBR SHAR SIPR are set here

 sdata = 0x00;
 spi_xmit(sdata);

 sdata = 0x01;
 spi_xmit(sdata);

 sdata = 0x04;
 spi_xmit(sdata);

 sdata = 0xC0;
 spi_xmit(sdata);

 sdata = 0xA8;
 spi_xmit(sdata);

 sdata = 0x00;
 spi_xmit(sdata);

 sdata = 0x01;
 spi_xmit(sdata);

}
void SUBR()
{

 sdata = 0x00;
 spi_xmit(sdata);

 sdata = 0x05;
 spi_xmit(sdata);

 sdata = 0x04;
 spi_xmit(sdata);

 sdata = 0xFF;
 spi_xmit(sdata);

 sdata = 0xFF;
 spi_xmit(sdata);

 sdata = 0xFF;
 spi_xmit(sdata);


 sdata = 0x00;
 spi_xmit(sdata);

}

void SHAR()
{
sdata = 0x00;
spi_xmit(sdata);

 sdata = 0x09;
 spi_xmit(sdata);

 sdata = 0x04;
 spi_xmit(sdata);

 sdata = 0x00;
 spi_xmit(sdata);

 sdata = 0x08;
 spi_xmit(sdata);

 sdata = 0xDC;
 spi_xmit(sdata);

 sdata = 0x01;
 spi_xmit(sdata);

 sdata = 0x02;
 spi_xmit(sdata);

 sdata = 0x03;
 spi_xmit(sdata);
}

void SIPR ()

{
sdata = 0x00;
spi_xmit(sdata);

 sdata = 0x0F;
 spi_xmit(sdata);

 sdata = 0x04;
 spi_xmit(sdata);

 sdata = 0xC0;
 spi_xmit(sdata);

 sdata = 0xA8;
 spi_xmit(sdata);

 sdata = 0x00;
 spi_xmit(sdata);

 sdata = 0x02;
 spi_xmit(sdata);

}

//===========================================================================
// *****************************************
void Sn_MR()
{
// Sn3_MR reg
sdata = 0x00;
spi_xmit(sdata);

	sdata = 0x00;
	spi_xmit(sdata);

	sdata = 0x04;
	spi_xmit(sdata);

	sdata = 0x01;
	spi_xmit(sdata);

}

void Sn_PORT()
{
sdata = 0x00;
spi_xmit(sdata);

sdata = 0x04;
spi_xmit(sdata);

sdata = 0x0C;
spi_xmit(sdata);

sdata = 0x13;
spi_xmit(sdata);

sdata= 0x88;
spi_xmit(sdata);

}

void opencmd()
{
//Sn_CR reg
sdata = 0x00;
spi_xmit(sdata);

	sdata = 0x01;
	spi_xmit(sdata);

	sdata = 0x0C;
	spi_xmit(sdata);

	sdata = 0x01;
	spi_xmit(sdata);

}

void Sn_DIPR()
{
//destination IP address
sdata = 0x00;
spi_xmit(sdata);

sdata = 0x0C;
spi_xmit(sdata);

sdata = 0x0C;
spi_xmit(sdata);

sdata = 0xC0;
spi_xmit(sdata);


sdata = 0xC0;
spi_xmit(sdata);

sdata = 0xA8;
spi_xmit(sdata);

sdata = 0x00;
spi_xmit(sdata);

sdata = 0x0B;
spi_xmit(sdata);

}

void Sn_DPORT()
{
//destination port number
sdata = 0x00;
spi_xmit(sdata);

sdata= 0x10;
spi_xmit(sdata);

sdata = 0x0C;
spi_xmit(sdata);

sdata = 0x13;
spi_xmit(sdata);

sdata = 0x88;
spi_xmit(sdata);

}

void listencmd () // working in tcp server mode changed to TCP client mode listen chnaged to connect
{
//Sn_CR
sdata = 0x00;
spi_xmit(sdata);

	sdata = 0x01;
	spi_xmit(sdata);

	sdata = 0x0C;
	spi_xmit(sdata);

	sdata = 0x04;
	spi_xmit(sdata);

}

//*******************************************************
void txdata ()
{
sdata = 0x00;
spi_xmit(sdata);

	sdata = 0x00;
	spi_xmit(sdata);

	sdata = 0x14;
	spi_xmit(sdata);

	sdata = 0xAA;
	spi_xmit(sdata);

	sdata = 0xAA;
	spi_xmit(sdata);

}

//*****************************************************

void sendcmd()
{
sdata = 0x00;
spi_xmit(sdata);

sdata = 0x01;
spi_xmit(sdata);

sdata = 0x0C;
spi_xmit(sdata);

sdata = 0x20;
spi_xmit(sdata);

}

// Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here:

void delay_loop()
{
long i;
for (i = 0; i < 1000000; i++) {}
}

void error(void)
{
__asm(" ESTOP0"); // Test failed!! Stop!
for (;;);
}

void spi_init()
{
SpiaRegs.SPICCR.all =0x0007; // Reset on, rising edge, 16-bit char bits
SpiaRegs.SPICTL.all =0x0006; // Enable master mode, normal phase,
// enable talk, and SPI int disabled.
SpiaRegs.SPIBRR =0x007F;
SpiaRegs.SPICCR.all =0x0097; // Relinquish SPI from Reset
SpiaRegs.SPIPRI.bit.FREE = 1; // Set so breakpoints don’t disturb xmission
}

void spi_xmit(uint8 a)
{
SpiaRegs.SPITXBUF=a;
}

void spi_fifo_init()
{
// Initialize SPI FIFO registers
SpiaRegs.SPIFFTX.all=0xE040;
SpiaRegs.SPIFFRX.all=0x204f;
SpiaRegs.SPIFFCT.all=0x0;
}

while reading PHY link am getting the value as link down
this is the frame i used to read the phy link status

void PHYCFGR()
{
sdata = 0x00;
spi_xmit(sdata);

sdata = 0x2E;
spi_xmit(sdata);

sdata = 0x00;
spi_xmit(sdata);

}

Hello
Please tell me about the problem with the program.
We can’t check all the codes.

Hello Teddy,

the spi communication is working fine as i read the version register value i got the correct value. but theTCP connection is not working.
Also when i reads the PHYCFGR the link status bit shows as link down.

Hello
If the SPI communication is fine, check hardware connected.

  1. Check Lan cable connected PC or router.
  2. Check the LED light of the Ethernet connector.
  3. Check your schematic. check your Ethernet connector has a transformer.

Thank you

basically this is what i did ,
1,Set MR reg value to 0x08; //for initializing the internal regs as per the datasgeet
2,wait for the MR reg to clear to 0x00 ;
3,Set IP MAC and GHAR;
4,Set Sn_MR value to 0x01; //TCP protocol
5,Set DPORT DIP ;
6; Issue open command
7,Delay
8Issue connect command.

But the problem is that am stuck at step 2. MR reg is not clearing to 0x00