View previous topic :: View next topic |
Author |
Message |
jeremywilson
Joined: 11 Jul 2011 Posts: 79 Location: United States
|
Posted: Mon Aug 26, 2019 4:46 pm Post subject: W5500 problems |
|
|
I can't get a ping response back from W5500 - program hangs at Config TCPIP line.
Is it okay to use software SPI for TCPIP?
Am I wrong in assuming that all I need is Config SPI and Config TCPIP to get a ping response?
Using ATMega2560 with 7,372,800 Hz crystal.
code fragment:
Code: | Config Spi = Soft , Din = Tcp_miso , Dout = Tcp_mosi , Ss = Tcp_cs , Clock = Tcp_sck , Mode = 0
'Reset TCP
Reset Tcp_reset : Waitms 1
Set Tcp_reset : Waitms 150
Config Tcpip = Noint , Mac = 139.2.21.67.189.253 , Ip = 10.0.16.155 , Submask = 255.255.255.0 , Gateway = 10.0.16.254 , Localport = 80 , Noinit = 0 , Chip = W5500 , Spi = 1 , Cs = Tcp_cs
'Config Tcpip = Noint , Mac = 0.8.220.77.05.33 , Ip = 0.0.0.0 , Submask = 0.0.0.0 , Gateway = 0.0.0.0 , Localport = 68 , Chip = W5500 , Spi = 1 , Cs = Tcp_cs
'Config Tcpip = Noint , Mac = 12.128.12.34.56.78 , Ip = 192.168.1.88 , Submask = 255.255.255.0 , Gateway = 192.168.1.1 , Localport = 1000 , Chip = W5500 , Spi = 1 , Cs = Tcp_cs
'Config Tcpip = Noint , Mac = 139.2.21.67.189.253 , Ip = 10.0.16.155 , Submask = 255.255.255.0 , Gateway = 10.0.16.254 , Localport = 80 , Noinit = 0 , Chip = W5500 , Spi = 1 , Cs = Tcp_cs
|
Thanks for you help! |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5914 Location: Holland
|
Posted: Mon Aug 26, 2019 7:33 pm Post subject: |
|
|
you can not use soft spi for TCP/IP.
It would slow down the traffic too much. _________________ Mark |
|
Back to top |
|
|
jeremywilson
Joined: 11 Jul 2011 Posts: 79 Location: United States
|
Posted: Mon Aug 26, 2019 10:23 pm Post subject: |
|
|
Is this the reason for the freeze?
Thanks for the info! |
|
Back to top |
|
|
jeremywilson
Joined: 11 Jul 2011 Posts: 79 Location: United States
|
Posted: Tue Aug 27, 2019 12:51 am Post subject: |
|
|
I've jumped the W5500 spi pins to the Atmel hardware spi pins:
Code: | Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 0 , Clockrate = 4 , Noss = 1
|
program still hanging at Config TCPIP. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5914 Location: Holland
|
Posted: Tue Aug 27, 2019 9:23 am Post subject: |
|
|
you should have a look at the samples.
Noss = 1 'check the help to find out what this means and what you need in that case.
or use Noss = 0 when using all the spi pins. _________________ Mark |
|
Back to top |
|
|
jeremywilson
Joined: 11 Jul 2011 Posts: 79 Location: United States
|
Posted: Tue Aug 27, 2019 5:23 pm Post subject: |
|
|
Forgot to comment out those lines in tcpip-w5500.LBX !
It's working now.
Thanks!! |
|
Back to top |
|
|
jeremywilson
Joined: 11 Jul 2011 Posts: 79 Location: United States
|
Posted: Wed Aug 28, 2019 6:00 pm Post subject: |
|
|
TCP/IP newbie still having problems. Any help very much appreciated !!!
On my "main router" network, my device gets an IP address ok (10.0.16.114), but it can only be pinged by computers on the same switch.
I made a separate "netgear" network, my device gets "DHCP ERROR", but it appears it was offered 192.168.1.51.
Looking at the Wireshark captures (attached), there are errors in the communication on both networks:
main router:
frame info
156 DHCP DISCOVER - END OPTION MISSING ERROR
157 DHCP OFFER
158 DHCP REQUEST - END OPTION MISSING ERROR
159 DHCP ACK
160
161 LEAVE GROUP 255.255.255.255 - SOURCE MAC MUST NOT BE GROUP ADDRESS WARNING & CHECKSUM INCORRECT ERROR
netgear:
frame info
114 DHCP DISCOVER - END OPTION MISSING ERROR
115 BROADCAST
116 DHCP OFFER
117 DHCP REQUEST - END OPTION MISSING ERROR
118 DHCP ACK
Code: | 'REQUIRED FIX:
'Open tcpip-w5500.LBX file with text editor,
'Search for label "_Re_init_tcpip_lp:" and remark ( the lines as shown:
' _Re_init_tcpip_lp:
' ; rcall _read_TCPSPIX
' ;.OBJ FCD7
' ; rjmp _Re_init_tcpip_lp
$nocompile
Declare Function Xidcookie_ok () As Byte
Declare Function Parse_dhcp_msg (byval Doption As Byte) As Byte
Declare Function Dhcp_ok () As Byte
'Declare Sub Print_parse()
Declare Sub Init_tcpip ()
'we will use the tt array only in the begin
Dim Tt (548) As Byte 'DHCP buffer
Dim Xid (4) As Byte
Dim Mac_add (6) As Byte
Dim Pa (4) As Byte
Dim Result As Word
Dim Ip (4) As Byte , Submask (4) As Byte , Gateway (4) As Byte
Dim Eth_ip (4) As Byte
Dim Eth_mask (4) As Byte
Dim Eth_gateway (4) As Byte
Dim Eth_port As String * 4
'Mac Address
'This number should match the one in the 'Config Tcpip...' line
'Do not use first byte
Mac_add (1) = &H00 '0
Mac_add (2) = &HA3 '8
Mac_add (3) = &HBE '220
Mac_add (4) = &HEF '77
Mac_add (5) = &HFE '05
Mac_add (6) = &HED '33
'Transaction ID
'This number should be random but we use the MAC address
Xid (1) = Mac_add (3) '220
Xid (2) = Mac_add (4) '77
Xid (3) = Mac_add (5) '05
Xid (4) = Mac_add (6) '33
Goto End_w5500_routines
'******************************************************************************
Sub Init_tcpip ()
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 0
Spsr = 1
Spiinit
Reset Tcp_reset : Waitms 1
Set Tcp_reset : Waitms 150
'we specify IP 0.0.0.0 and gateway 0.0.0.0. Really important is to use local port 68 !
Config Tcpip = Noint , Mac = 0.8.220.77.05.33 , Ip = 0.0.0.0 , Submask = 0.0.0.0 , Gateway = 0.0.0.0 , Localport = 68 , Chip = W5500 , Spi = 1 , Cs = Tcp_cs
Wait 2
End Sub
'******************************************************************************
Function Dhcp_ok () As Byte
Local Btmp As Byte
Local Try As Byte
Dhcp_ok = 0 'assume error
If Getsocket(0 , Sock_dgram , 68 , 0) = 0 Then
For Result = 1 To 548 'clear buffer
Tt (result ) = 0
Next
Try = 0
Do
Btmp = Socketstat(0 , Sel_control )
If Btmp = Sock_udp Then Exit Do
Waitms 10
Incr Try
Loop Until Try > 100
'DHCP
Tt (1) = 1 'Dhcp_pack_request
Tt (2) = 1 ' Dhcp_htype10mb
Tt (3) = 6 ' 'mac address lenght Dhcp_hlenethernet
Tt (4) = 0 'Dhcp_hops
Tt (5) = Xid (1)
Tt (6) = Xid (2)
Tt (7) = Xid (3)
Tt (8) = Xid (4)
Tt (11) = &H80 'dhcp flags
Tt (29) = Mac_add (1) 'MAC address
Tt (30) = Mac_add (2)
Tt (31) = Mac_add (3)
Tt (32) = Mac_add (4)
Tt (33) = Mac_add (5)
Tt (34) = Mac_add (6)
Tt (237) = 99 'DHCP cookie
Tt (238) = 130
Tt (239) = 83
Tt (240) = 99
Tt (241) = 53 'options Dhcpmessagetype
Tt (242) = 1
Tt (243) = 1 'Dhcp_discover
Tt (244) = 55 'Dhcpparamrequest
Tt (245) = 4 ' Request list
Tt (246) = 1 'Subnet mask
Tt (247) = 3 'Default Gateway router
Tt (248) = 6 'DNS server
Tt (249) = 255 'end options
Try = 0
Do
Incr Try
Result = Udpwrite(255.255.255.255 , 67 , 0 , Tt (1) , 548 )
'Print "(" ; Result ; " bytes)"
For Btmp = 1 To 100
Waitms 10
Result = Socketstat(0 , Sel_recv )
If Result > 0 Then Exit For
Next
Loop Until Result > 0 Or Try > 9
If Result > 0 Then
'Print "<-- Receive DHCP Offer (" ; Result ; " bytes)"
Udpreadheader 0 ' read the udp header
Result = Result - 8
Result = Udpread(0 , Tt (1) , Result )
If Tt (1) = 2 Then 'DHCP pack reply
If Xidcookie_ok () = 1 Then 'same XactionID
If Tt (241) = 53 Then ' Dhcp_offer_ok Dhcpmessagetype
If Tt (242) = 1 Then
If Tt (243) = 2 Then ' Dhcp_offer
Tt (1) = 1 'Dhcp_pack_request
Tt (13) = Tt (17) 'IP client
Tt (14) = Tt (18)
Tt (15) = Tt (19)
Tt (16) = Tt (20)
Tt (17) = 0 'my IP
Tt (18) = 0
Tt (19) = 0
Tt (20) = 0
Tt (241) = 53 ' Dhcpmessagetype options
Tt (242) = 1
Tt (243) = 3 'Dhcp_request
Tt (244) = 55 'Dhcpparamrequest
Tt (245) = 4
Tt (246) = 1 'Subnetmask
Tt (247) = 3 'Router
Tt (248) = 6 'Dns
Tt (249) = 255 'Endoption
For Result = 250 To 548 'refill
Tt (result ) = 0
Next
Result = Udpwrite(255.255.255.255 , 67 , 0 , Tt (1) , 548 )
'Print "(" ; Result ; " bytes)"
For Btmp = 1 To 100
Waitms 10
Result = Socketstat(0 , Sel_recv )
If Result > 0 Then Exit For
Next
If Result > 0 Then
'Print "<-- Receive DHCP Pack (" ; Result ; " bytes)"
'Clearbuff
Udpreadheader 0 ' read the udp header
Result = Result - 8
Result = Udpread(0 , Tt (1) , Result )
If Tt (1) = 2 Then 'DHCP pack reply?
If Xidcookie_ok () = 1 Then 'same XactionID?
If Tt (241) = 53 Then 'Dhcpmessagetype DHCPACK
If Tt (242) = 1 Then
If Tt (243) = 5 Then ' Dhcp_ack
Pa (1) = Tt (20) 'Get IP in buffer
Pa (2) = Tt (19)
Pa (3) = Tt (18)
Pa (4) = Tt (17)
Btmp = Memcopy(pa (1) , Ip (1) , 4 , 3)
'Print "My IP: ";
'Print_parse
If Parse_dhcp_msg (1) = 1 Then 'subnet mask
'Print "Sub Net Mask: ";
'Print_parse
Btmp = Memcopy(pa (1) , Submask (1) , 4 , 3)
End If
If Parse_dhcp_msg (3) = 1 Then 'router
'Print "Default Gateway: ";
'Print_parse
Btmp = Memcopy(pa (1) , Gateway (1) , 4 , 3)
End If
If Parse_dhcp_msg (54) = 1 Then 'dhcpserveridentifier
'Print "DHCP Server: ";
'Print_parse
End If
If Parse_dhcp_msg (6) = 1 Then 'DNS
'Print "DNS Server: ";
'Print_parse
End If
'Print "Reconfig..."
Settcp Mac_add (1) , Ip (1) , Submask (1) , Gateway (1)
Dhcp_ok = 1
'*****************************************************************************
'* At this point, the Wxx00, responds to the new IP
'* provided by the DHCP server.
'* You can check this with PING
'*****************************************************************************
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
Closesocket 0 'do not forget to close the socket
End Function
'******************************************************************************
Function Xidcookie_ok () As Byte
Xidcookie_ok = 0
If Tt (5) = Xid (1) Then
If Tt (6) = Xid (2) Then
If Tt (7) = Xid (3) Then
If Tt (8) = Xid (4) Then 'end of XID check
If Tt (237) = 99 Then 'cookie check
If Tt (238) = 130 Then
If Tt (239) = 83 Then
If Tt (240) = 99 Then
Xidcookie_ok = 1
End If
End If
End If
End If
End If
End If
End If
End If
End Function
'******************************************************************************
Function Parse_dhcp_msg (byval Doption As Byte) As Byte
Local Ax As Word
Local Ay As Byte
Pa (1) = 0
Pa (2) = 0
Pa (3) = 0
Pa (4) = 0
Parse_dhcp_msg = 0
Ax = 244
Do
Ay = Tt (ax )
If Ay = 255 Then Exit Do
If Ay = Doption Then
Ax = Ax + 5 '2
Pa (1) = Tt (ax )
Decr Ax
Pa (2) = Tt (ax )
Decr Ax
Pa (3) = Tt (ax )
Decr Ax
Pa (4) = Tt (ax )
Parse_dhcp_msg = 1
Exit Do
End If
Incr Ax
Ay = Tt (ax )
Ax = Ax + Ay
Incr Ax
If Ax > 548 Then Exit Do
Loop
End Function
'******************************************************************************
'Sub Print_parse()
' Print Pa(4) ; "." ; Pa(3) ; "." ; Pa(2) ; "." ; Pa(1) ; " "
'End Sub
'******************************************************************************
End_w5500_routines : |
|
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5914 Location: Holland
|
Posted: Wed Aug 28, 2019 8:08 pm Post subject: |
|
|
The art of reading
'This number should match the one in the 'Config Tcpip...' line
it means that they need to have the same mac address. _________________ Mark |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|