TCP Example


I would like get example c project for W5500io TCP Server, because I have no idea how wrote program for my W5500io.

I write my Pseudocode example:

Init function:
Sn_Mr set on TCP
Sn_Port0 set on 80
Sn_CR set OPEN

Listen function:
Sn_CR set Listen

Established test function:
if(Sn_SR == Established)

OK and now, I don’t know, how I receive data?

1 Like

You gave a look here : [url][/url]
There are two examples one for DHCP and the other for DNS that contain most of the C ++ functions that you need.
Still lack a bit before your macro instructions you must…

  • set the MAC address
  • set an IP address for your device
  • set the gateway addr
  • set subnet mask

…or implement DHCP

Then after you’ve written in your post make a loop on ever opened socket and verify when that pass to established.
So staying in the area of macro language …

   While true
      for sockreg as byte = 0 to (MAX_SOCK_NUM - 1)
         sockstat as byte = ReadSocketReg(sockreg, Sn_SR)
         Select sockstat
         Case SOCK_CLOSED
            If Socket(sockreg, Sn_MR_TCP, TCP_PORT, 0) Then     // Reenter a closed socket in listen mode
               If Not Listen(sockreg) Then
               End If
            End If
         Case SOCK_ESTABLISHED       
            rsize as UShort = ReadSocketword(sockreg,Sn_RX_RSR0) // Get Recv Size
            If rsize > 0 Then
                  rxpointer as UShort = ReadSocketword( sockreg, Sn_RX_RD0 )     // First byte RX Buffer location
	                 incoming stream is here at rxpointer
	                 WIZCHIP_READ_BUF and other memory access function :
	                 Socket related functions:
                  rxpointer = rxpointer  + 1 
                  WritesocketWord(sockreg, Sn_RX_RD0, rxpointer )  // Increase readed position
                  WriteSocketReg(sockreg, Sn_CR, Sn_CR_RECV)       // W5500 move the RX pointer 
                  While(ReadSocketReg(sockreg, Sn_CR) <> 0 )
                  End While                             
            End If
         Case SOCK_FIN_WAIT,
	                WriteSocketReg(sockreg,  Sn_CR, Sn_CR_CLOSE)  // Close this socket
    	            While(ReadSocketReg(sockreg, Sn_CR) <> 0)
    	            End While         
         End Select          
      Next sockreg    
   End While

WIZCHIP_READ_BUF and other memory access functions :
Socket related functions:

…if you need anything else let me know.
Good job.

Thank you for your reply,
When I try everything you said, I will reply again.

But firstly I would like to test the connection with W5500io over SPI, how can I do that? Maybe by sending a question and recieving an answer.

I tested W5500io with pinging. I connected the module on the supply and the router, I used pinging and the device responded well.
Now I would like to test the SPI communication. How?

I’ve seen that uses Arduino 2 and I not have present at that point this MPU is about W5500 but I’m sure there is a working library for W5100 with Arduino One and then from there you can go to drive SPI.
Functions for drive a W5500 throw an SPI module is here [url][/url]
In this module you can find function for transfer a buffer like wiz_send_data, wiz_recv_data , function for registers like getSn_TX_FSR and getSn_RX_RSR
Get to :

  • know better Arduino 2 SPI library
  • starts from WIZCHIP_READ and WIZCHIP_WRITE and modify them with calls to Arduino 2 SPI library
    Then you are ready to read and write in W5500 registers ( IP, MAC and gateway registers).
    It is what I have done to adapt the library to PIC24 family.

I want to develop the application using Atmega328p. Are the libraries the same? Thanks

In this I can not help you because I do not know ATMEGA328P and even the development system for Arduino One or Arduino 2.
As I told… the operating principle is described in GitHub sources for the W5500 that is the basis.
You have to see if there is already a W5500 library for ATMEGA328P or use the standard SPI library of your MPU to write a library from scratch.