W5500

SwordfishUser.W5500 History

Show minor edits - Show changes to output

Changed line 10 from:
This library is [[http://sfcompiler.co.uk/phpBB3/viewtopic.php?f=5&t=1944 | compatible ]]with this hardware also
to:
This library is [[http://sfcompiler.co.uk/phpBB3/viewtopic.php?f=5&t=1944 | compatible ]] with this hardware also
Added lines 9-10:

This library is [[http://sfcompiler.co.uk/phpBB3/viewtopic.php?f=5&t=1944 | compatible ]]with this hardware also
Changed lines 823-824 from:
SetAddress(192,168,1,50,@PingAddr)
to:

SetAddress(192,168,1,50,@PingAddr) ' <-- CHANGE YOUR REQ.PING ADDRESS
Changed lines 704-705 from:
[[http://sfcompiler.co.uk/wiki/uploads/coccoliso/W5500-Library.zip | W5500-Library ]]
to:
[[http://sfcompiler.co.uk/wiki/uploads/coccoliso/W5500-with-ping-support.zip | W5500-Library ]]
Changed lines 711-773 from:
Edit W5500-Socket.bas module and add Connect() function to connect via TCP client.
On the module top add :
=code [=
Include "EEPROM.bas"

#option TCP_PORT_ROM_ADDR = 0

Private Const
    iniTcpPort  As Word = 1000,
    endTcpPort  As Word = 2000,
    eePortAddr  = TCP_PORT_ROM_ADDR
=]

On the module bottom add:
=code [=
{
****************************************************************************
* Name    : ComputeLocalPort                                              *
* Purpose :                                                                *
****************************************************************************
}
Private Function ComputeLocalPort() As Word
    ComputeLocalPort = EE.ReadWord(eePortAddr)
    If (ComputeLocalPort < iniTcpPort) Or (ComputeLocalPort > endTcpPort) Then
        ComputeLocalPort = iniTcpPort
    Else
        Inc(ComputeLocalPort)
    End If
    EE.WriteWord(eePortAddr, ComputeLocalPort)
End Function

{
****************************************************************************
* Name    : Connect                                                        *
* Purpose :                                                                *
****************************************************************************
}
Public Function Connect(sock As Byte,
                        pArrIPAddr As Word,
                        _port As Word,
                        flag As Byte) As Boolean
    result = false
       
    If Socket(sock, cSn_MR_TCP, ComputeLocalPort(), $00) Then 
    WriteSocketPtr(sock, rSn_DIPR0, pArrIPAddr, 4)
    WriteSocketReg(sock, rSn_DPORT0, Byte(_port>>8))
        WriteSocketReg(sock, rSn_DPORT0 + 1, Byte(_port And $00FF))           
        WriteSocketReg(sock, rSn_CR, cSn_CR_CONNECT)   
        While(ReadSocketReg(sock,rSn_CR) = 1 )    // 30/11/2014
        End While
           
        While ReadSocketReg(sock, rSn_SR)<> cSOCK_ESTABLISHED
            If (ReadSocketReg(sock, rSn_IR) And cSn_IR_TIMEOUT ) <> 0 Then
                result = false
                Exit
            End If
        End While   
        result = true
    End If
End Function
=]

These routines allow you to perform a client connection and increase the local port at the last use, avoiding the connection timeout on the server side socket eventually left open earlier.
to:

Added routines to allow a TCP client connection and increase the local port at the last use, avoiding the connection timeout on the server side socket eventually left open earlier.

!!! Updated with PING functionality - March 27, 2015

[[http://sfcompiler.co.uk/wiki/uploads/coccoliso/W5500-Test-Ping-Program.zip |Here]] you will find PING functionality test program.

Changed line 1 from:
'+Updated with TCP socket connection - February 28, 2015 (see at bottom)+'
to:
'+Updated with TCP socket connection - February 28, 2015 +'
Added line 39:
||W5500-Ping.bas ||IPRAW mode ping module (27/3/2015)||
Changed line 784 from:
*  Notice  : Copyright (c) 2014                                            *
to:
*  Notice  : Copyright (c) 2015                                            *
Changed line 786 from:
*  Date    : 1/11/2014                                                     *
to:
*  Date    : 27/03/2015                                                    *
Changed line 778 from:
=Code [=
to:
=code [=
Changed lines 776-892 from:
[[http://sfcompiler.co.uk/wiki/uploads/coccoliso/W5500-Test-Ping-Program.zip |Here]] you will find PING functionality test program.
to:
[[http://sfcompiler.co.uk/wiki/uploads/coccoliso/W5500-Test-Ping-Program.zip |Here]] you will find PING functionality test program.

=Code [=
{
*****************************************************************************
*  Name    : W5500-Test-Ping.BAS                                            *
*  Author  : Coccoliso                                                      *
*  Notice  : Copyright (c) 2014                                            *
*          : All Rights Reserved                                            *
*  Date    : 1/11/2014                                                      *
*  Version : 1.0                                                            *
*  Notes  :                                                                *
*          :                                                                *
*****************************************************************************
}
Device = 18f2682
Clock = 40

#option WIZ_DHCP_DEBUG  = true
#option WIZ_DNS_DEBUG  = false
#option WIZ_PING_DEBUG  = false
#option WIZ_PING_DISPLAY = true

#option USE_DHCP = true
#option USE_DNS  = false
#option USE_PING = true
#option WIZ_SCS_PIN = PORTC.0
#option WIZ_RST_PIN = PORTC.1 

Include "Config_NOWDT"
Include "W5500-Consts"
Include "W5500-Utils"
Include "W5500"

Include "usart"
Include "convert"
Include "string"


#if USE_DNS
    Include "W5500-DNSConsts"
    Dim dnsRes As DNS_INFO
#endif

Private Sub ConfigDisplay()
    USART.Write(#13,#10)
    USART.Write("MAC Address ",SARtoString(),#13,#10)
    USART.Write("IP Address  ",SIPRtoString(),#13,#10)
    USART.Write("Subnet Mask ",SUBRtoString(),#13,#10)
    USART.Write("Gateway    ",GARtoString(),#13,#10)
    USART.Write("DNS Address ",AddrToString(@Dns_Addr),#13,#10)
    USART.Write(#13,#10)   
End Sub

#if USE_DHCP
Sub OnUpdate()
    ConfigDisplay()
End Sub

Sub OnConflict()
End Sub
#endif

Private Function SetAddress(a,b,c,d As Byte, RAMAddr As Word) As Word 
    result = RAMAddr
    Save(FSR2)
    FSR2 = RAMAddr
    POSTINC2 = a
    POSTINC2 = b
    POSTINC2 = c
    INDF2 = d
    Restore           
End Function

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

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

Dim PingAddr(4)  As Byte
USART.SetBaudrate(br115200)

#if USE_DHCP = true
    USART.Write("Now find the DHCP server.. ",13,10)   
    DHCPSetEvents(@OnUpdate, @OnConflict)
    If DHCPTask(3) = false Then
        USART.Write("DHCP error, so must set static parms.. ",13,10)
        ConfigDisplay()
    End If   
#else
    USART.Write("Using static config.. ",13,10)   
    ConfigDisplay()
#endif

DelayMS(1000)

#if USE_DNS
    USART.Write("DNSResolving for www.google.com ... ")
    dnsRes = DNSResolve("www.google.com")
    If dnsRes.STATUS = cRC_NO_ERROR Then
        USART.Write(AddrToString(@dnsRes.IPAddr.Byt),13,10)
    Else
        USART.Write("unable to resolve (ERR=",DecToStr(dnsRes.STATUS),")",13,10)   
    End If
#endif
USART.Write(13,10)
USART.Write("My IP is ",SIPRtoString(),13,10)

SetAddress(192,168,1,50,@PingAddr)

USART.Write("Now call PingAuto()..",13,10)
PingAuto(@PingAddr)
USART.Write("Now call PingCount() with 10 pings on Socket 0 ..",13,10)
PingCount(0,10,@PingAddr)
USART.Write("That is all!",13,10)
While true
End While
=]
Changed line 776 from:
Here Attach:file.ext you will find PING functionality and test program.
to:
[[http://sfcompiler.co.uk/wiki/uploads/coccoliso/W5500-Test-Ping-Program.zip |Here]] you will find PING functionality test program.
Changed lines 8-9 from:
[[http://sfcompiler.co.uk/wiki/uploads/coccoliso/W5500-Library.zip | W5500-Library ]]
to:
[[http://sfcompiler.co.uk/wiki/uploads/coccoliso/W5500-with-ping-support.zip | W5500-Library ]]
Changed line 776 from:
In this [[http://sfcompiler.co.uk/phpBB3/viewtopic.php?f=4&t=1942&p=10718#p10718| this post ]] you will find the latest W5500 library update with PING functionality and test program.
to:
Here Attach:file.ext you will find PING functionality and test program.
Changed lines 2-3 from:
'+Updated with PING functionality - March 27, 2015 (see at bottom+'
to:

'+Updated with PING functionality - March 27, 2015 (see at bottom)+'
Changed lines 774-776 from:
!!! Updated with PING functionality

'''UPDATED 27
March 2015'''
to:
!!! Updated with PING functionality - March 27, 2015
Changed lines 2-3 from:
to:
'+Updated with PING functionality - March 27, 2015 (see at bottom+'
Added lines 773-777:
!!! Updated with PING functionality

'''UPDATED 27 March 2015'''

In this [[http://sfcompiler.co.uk/phpBB3/viewtopic.php?f=4&t=1942&p=10718#p10718| this post ]] you will find the latest W5500 library update with PING functionality and test program.
Deleted line 0:
'+Updated with multi socket SOAP - January 30, 2015+'
Changed line 707 from:
'+Updated with TCP socket connection - February 28, 2015 +'
to:
!!!Updated with TCP socket connection - February 28, 2015
Changed lines 2-3 from:
to:
'+Updated with TCP socket connection - February 28, 2015 (see at bottom)+'
Added lines 708-771:
'+Updated with TCP socket connection - February 28, 2015 +'
Edit W5500-Socket.bas module and add Connect() function to connect via TCP client.
On the module top add :
=code [=
Include "EEPROM.bas"

#option TCP_PORT_ROM_ADDR = 0

Private Const
    iniTcpPort  As Word = 1000,
    endTcpPort  As Word = 2000,
    eePortAddr  = TCP_PORT_ROM_ADDR
=]

On the module bottom add:
=code [=
{
****************************************************************************
* Name    : ComputeLocalPort                                              *
* Purpose :                                                                *
****************************************************************************
}
Private Function ComputeLocalPort() As Word
    ComputeLocalPort = EE.ReadWord(eePortAddr)
    If (ComputeLocalPort < iniTcpPort) Or (ComputeLocalPort > endTcpPort) Then
        ComputeLocalPort = iniTcpPort
    Else
        Inc(ComputeLocalPort)
    End If
    EE.WriteWord(eePortAddr, ComputeLocalPort)
End Function

{
****************************************************************************
* Name    : Connect                                                        *
* Purpose :                                                                *
****************************************************************************
}
Public Function Connect(sock As Byte,
                        pArrIPAddr As Word,
                        _port As Word,
                        flag As Byte) As Boolean
    result = false
       
    If Socket(sock, cSn_MR_TCP, ComputeLocalPort(), $00) Then 
    WriteSocketPtr(sock, rSn_DIPR0, pArrIPAddr, 4)
    WriteSocketReg(sock, rSn_DPORT0, Byte(_port>>8))
        WriteSocketReg(sock, rSn_DPORT0 + 1, Byte(_port And $00FF))           
        WriteSocketReg(sock, rSn_CR, cSn_CR_CONNECT)   
        While(ReadSocketReg(sock,rSn_CR) = 1 )    // 30/11/2014
        End While
           
        While ReadSocketReg(sock, rSn_SR)<> cSOCK_ESTABLISHED
            If (ReadSocketReg(sock, rSn_IR) And cSn_IR_TIMEOUT ) <> 0 Then
                result = false
                Exit
            End If
        End While   
        result = true
    End If
End Function
=]

These routines allow you to perform a client connection and increase the local port at the last use, avoiding the connection timeout on the server side socket eventually left open earlier.
Changed lines 91-93 from:
*  Date    : 1/11/2014                                                     *
*  Version : 1.0                                                            *
*  Notes  :                                                                *
to:
*  Date    : 30/01/2015                                                    *
*  Version : 2.0                                                            *
*  Notes  : All 8 sockets can be used for a multi socket server            *
Changed lines 413-415 from:
*  Date    : 14/10/2014                                                    *
*  Version : 1.0                                                            *
*  Notes  :                                                                *
to:
*  Date    : 30/01/2015                                                    *
*  Version : 2.0                                                            *
*  Notes  : All 8 sockets can used for multi socket SOAP server            *
Added lines 1-2:
'+Updated with multi socket SOAP - January 30, 2015+'
Changed lines 142-145 from:
// ############################################################################

// ############################################################################
to:
// ##################################################################################

// ##################################################################################
Changed lines 156-157 from:
Dim SDSeq      As Byte
to:
Changed lines 201-202 from:
           SockTimeoutEnable()
to:
           SockTimeoutEnable(sockreg)
Changed lines 309-310 from:
               SockTimeoutDisable()
to:
               SockTimeoutDisable(sockreg)
Changed line 322 from:
   If SockTimeout() Then
to:
   If SockTimeout(sockreg) Then
Changed line 324 from:
       SockTimeoutDisable()
to:
       SockTimeoutDisable(sockreg)
Changed lines 511-516 from:
   sockstat=ReadSocketReg(sockreg, rSn_SR)
 
  Select sockstat
    Case cSOCK_CLOSED
        If Socket(sockreg, cSn_MR_TCP, TCP_PORT, 0) Then
           If Not Listen(sockreg) Then
     
          DelayMS(1)
to:
   For sockreg= 0 To 7
        sockstat=ReadSocketReg(sockreg, rSn_SR)
        Select sockstat
   
    Case cSOCK_CLOSED
           If Socket(sockreg, cSn_MR_TCP, TCP_PORT, 0) Then
               If Not Listen(sockreg) Then
                    DelayMS(1)
                End If
Changed lines 520-551 from:
       End If
    Case cSOCK_ESTABLISHED     
       rsize = W5500.DataAvailable(sockreg)
        If rsize > 0 Then
 
           SockTimeoutEnable()
{
    Remember that the SOAP module works directly
    on the receive buffer and can be used on only
 
  one socket at a time because it keeps the
    socket number in a static variable which is set

   through the CheckEnvelope() function.
       
       
    If CheckEnvelope(sockreg) Then
               If CheckMethod("Command", iMethod) Then
{
    Client send a Command method
    request so check cCommand
    as integer parameter
}
               
                    If GetValue(iMethod,"cCommand",cCommand) Then
 
                     USART.Write("cCommand=",DecToStr(cCommand),#13,#10)
                    Else
                        USART.Write("cCommand=","INVALID",#13,#10)
                   End If                 
{
    now check cParm as integer
    parameter
}
               
                   If GetValue(iMethod, "cParm",cParm) Then
                       USART.Write("cParm=",DecToStr(cParm),#13,#10)
                    Else
                     USART.Write("cParm=","INVALID",#13,#10)
to:
       Case cSOCK_ESTABLISHED      
            rsize = W5500.DataAvailable(sockreg)
            If rsize > 0 Then
               SockTimeoutEnable(sockreg)
 
  {
       Remember that the SOAP module works directly
       on the receive buffer and can be used on only
   
    one socket at a time because it keeps the
        socket number in a static variable which is set
      through the CheckEnvelope() function.
    }          
   
           If CheckEnvelope(sockreg) Then
                    If CheckMethod(sockreg, "Command", iMethod) Then
    {
        Client send a Command method
        request so check cCommand
        as integer parameter
    }               
                        If GetValue(sockreg, iMethod,"cCommand",cCommand) Then
                           USART.Write("cCommand=",DecToStr(cCommand),#13,#10)
                     Else
                            USART.Write("cCommand=","INVALID",#13,#10)
                       End If                 
   {
        now check cParm as integer
        parameter
    }               
                        If GetValue
(sockreg, iMethod, "cParm",cParm) Then
                            USART.Write("cParm="
,DecToStr(cParm),#13,#10)
                        Else
                            USART.Write("cParm=","INVALID",#13,#10)
                        End If
                        W5500.ReleaseRXBuffer(sockreg)
    {
        Command method wants as answer
        a single Boolean value
        so create the response with
        single boolean result
    }                                 
                        W5500_SOAP.Initialize(sockreg, "Command")
                        W5500_SOAP.WriteResult(sockreg, true)
                        W5500_SOAP.Finalize(sockreg)
                        Disconnect(sockreg)                 
                        SockTimeoutDisable(sockreg
)
Changed lines 565-576 from:
                   W5500.ReleaseRXBuffer(sockreg)
{
    Command method wants as answer
    a single Boolean value
    so create the response with
    single boolean result
}                                 
                    W5500_SOAP.Initialize("Command")
                    W5500_SOAP.WriteResult(true)
                    W5500_SOAP.Finalize()
                    Disconnect(sockreg)                 
                    SockTimeoutDisable()
to:
  
                    If CheckMethod(sockreg, "Status", iMethod) Then
                        W5500.ReleaseRXBuffer(sockreg)
    {
        Client send a Status method
        request without parameters
        but want a complex object
        as response
    }               
                        W5500_SOAP.Initialize(sockreg, "Status")
    {
        Prepare four integer values
    }                   
                        W5500_SOAP.WriteElement(sockreg, "PointsNum",0)
                        W5500_SOAP.WriteElement(sockreg, "Chiamate",0)
                        W5500_SOAP.WriteElement(sockreg, "InAttesa",0)
                        W5500_SOAP.WriteElement(sockreg, "Visore",0)
    {
        Prepare two boolean values
    }                   
                        W5500_SOAP.WriteElement(sockreg, "Buzzer", false)
                        W5500_SOAP.WriteElement(sockreg, "Flash", false)
    {
        Now prepare a ListOf(integer)
        named ListaChiamate
    }
                       
                        W5500_SOAP.WriteElementOpen(sockreg, "ListaChiamate")
                        W5500_SOAP.WriteItem(sockreg,0)
                        W5500_SOAP.WriteItem(sockreg,1)
                        W5500_SOAP.WriteItem(sockreg,2)
                        W5500_SOAP.WriteItem(sockreg,3)
                        W5500_SOAP.WriteElementClose(sockreg, "ListaChiamate")
    {
        Now prepare a ListOf(integer)
        named ListaAttese
    }
                        W5500_SOAP.WriteElementOpen(sockreg, "ListaAttese")
                        W5500_SOAP.WriteItem(sockreg, 5)
                        W5500_SOAP.WriteElementClose(sockreg, "ListaAttese")
                        W5500_SOAP.Finalize(sockreg)
                        Disconnect(sockreg)                 
                        SockTimeoutDisable(sockreg)
                    End If
Changed lines 610-665 from:

                If CheckMethod("Status", iMethod) Then
                    W5500.ReleaseRXBuffer(sockreg)
{
    Client send a Status method
    request without parameters
    but want a complex object
    as response
}               
                    W5500_SOAP.Initialize("Status")
{
    Prepare four integer values
}                   
                    W5500_SOAP.WriteElement("PointsNum",0)
                    W5500_SOAP.WriteElement("Chiamate",0)
                    W5500_SOAP.WriteElement("InAttesa",0)
                    W5500_SOAP.WriteElement("Visore",0)
{
    Prepare two boolean values
}                   
                    W5500_SOAP.WriteElement("Buzzer", false)
                    W5500_SOAP.WriteElement("Flash", false)
{
    Now prepare a ListOf(integer)
    named ListaChiamate
}
                   
                    W5500_SOAP.WriteElementOpen("ListaChiamate")
                    W5500_SOAP.Write(0,1,2,3)
                    W5500_SOAP.WriteElementClose("ListaChiamate")
{
    Now prepare a ListOf(integer)
    named ListaAttese
}
                    W5500_SOAP.WriteElementOpen("ListaAttese")
                    W5500_SOAP.WriteItem(5)
                    W5500_SOAP.WriteElementClose("ListaAttese")
                    W5500_SOAP.Finalize()
                    Disconnect(sockreg)                 
                    SockTimeoutDisable()
                End If
            End If
        End If             
    Case cSOCK_FIN_WAIT,
        cSOCK_CLOSING,
        cSOCK_TIME_WAIT,
        cSOCK_CLOSE_WAIT,
        cSOCK_LAST_ACK
        Close(sockreg)
    End Select
   
    If SockTimeout() Then
        Close(sockreg)
        SockTimeoutDisable()
    End If
   
to:
           End If             
        Case cSOCK_FIN_WAIT,
            cSOCK_CLOSING,
            cSOCK_TIME_WAIT,
            cSOCK_CLOSE_WAIT,
            cSOCK_LAST_ACK
            Close(sockreg)
        End Select
       
        If SockTimeout(sockreg) Then
            Close(sockreg)
            SockTimeoutDisable(sockreg)
        End If   
    Next
Changed lines 1-2 from:
This library allow the use of the WIZnet / W550io in Swordfish that mount W5500 ethernet chip. The W5500 has within it all the logic related to the TCP client / server and responds to the ping without special drivers, can enable wake on lan feature and it is for this reason that lends itself to be used quickly and without a great deal of memory. Compared to his older brother W5100 (for which you will find the SF library [[http://www.sfcompiler.co.uk/wiki/pmwiki.php?n=SwordfishUser.W5100// | here ]]) has far fewer pins, a simple buffer management (no more fraction) allowing direct access to the memory in a sequential manner and more available sockets.
to:
This library allow the use of the WIZnet / WIZ550io in Swordfish that mount W5500 ethernet chip. The W5500 has within it all the logic related to the TCP client / server and responds to the ping without special drivers, can enable wake on lan feature and it is for this reason that lends itself to be used quickly and without a great deal of memory. Compared to his older brother W5100 (for which you will find the SF library [[http://www.sfcompiler.co.uk/wiki/pmwiki.php?n=SwordfishUser.W5100// | here ]]) has far fewer pins, a simple buffer management (no more fraction) allowing direct access to the memory in a sequential manner and more available sockets.
Changed line 8 from:
In particular, I have used through a module sold by the same WIZnet called W550io that mounts over chip and ethernet connector with all necessary circuitry. The module has two connectors strips with 1x6 pin and 1x8 pins.
to:
In particular, I have used through a module sold by the same WIZnet called WIZ550io that mounts over chip and ethernet connector with all necessary circuitry. The module has two connectors strips with 1x6 pin and 1x8 pins.
Changed line 409 from:
*  Author  : M.Cerutti                                                      *
to:
*  Author  : Coccoliso                                                      *
Changed line 22 from:
Surely the use of W5500 with PIC18 is an advantage because compared to the [[http://www.sfcompiler.co.uk/wiki/pmwiki.php?n=SwordfishUser.W5100| W5100 version ]] with this chip you can avoid allocating the receive buffer. In the main program with options you can disable DNS and/or DHCP freely for more memory.
to:
Surely the use of W5500 with PIC18 is an advantage because compared to the [[http://www.sfcompiler.co.uk/wiki/pmwiki.php?n=SwordfishUser.W5100| W5100 version ]] with this chip you can avoid allocating the receive buffer. In the main program with options you can also disable DNS and/or DHCP freely for more memory.
Changed line 22 from:
Surely the use of W5500 with PIC18 is an advantage because compared to the W5100 this chip you can avoid allocating the receive buffer. In the main program with options you can disable DNS and/or DHCP freely.
to:
Surely the use of W5500 with PIC18 is an advantage because compared to the [[http://www.sfcompiler.co.uk/wiki/pmwiki.php?n=SwordfishUser.W5100| W5100 version ]] with this chip you can avoid allocating the receive buffer. In the main program with options you can disable DNS and/or DHCP freely for more memory.