Question about Wiz820io (from Post #3)
twc
Posts: 107
I'm just checking out some of these demos and having some problems. I noticed there are netparms (ip, gateway, mask) etc. defined in DAT section of W5200. And I also see wiz.SetIp and wiz.SetMac at the beginning of TCPSocketClientDemoDhcpDns. I substituted my own netparms in both places. I thought you wouldn't need any of this (except Mac) by virtue of using DHCP. The failure mode is a second or so after "Requesting IP..." appears, the program just prints garbage infinitely. With DHCPDemo.spin it displays a buffer, and then ends up bytes received = -1 fail safe.
Comments
If the DhcpDemo returns (-1) it timed out. Please, verify your configuration.
Do you have the SPI I/O setup correctly?
First, thanks for your most excellent support for everyone Mike, definitely above and beyond!
Below you can see output from 1. TCPSocketClientDemoDhcpDns and 2. DhcpDemo. The garbage seems endlessly repeating in both cases.
I have confirmed the wiring. I should mention this Prop+Wiz820io setup is working with another program I wrote using PropGCC. I'd used different pins (and my own SPI driver), but I changed the PropGCC program to use the same pins as your demo and it is working. I'd wondered about nRESET and PWDN (which I control in my PropGCC program) but indeed my program works without them too (i.e. PWDN=GND, nRESET=floating)..
I'd thought about SPI/speed issues so I a) tried slowing the clock (pll8x) and b) using spi.spin - behavior same, just slower.
Does the progress of the programs before they 'crash' (infinite repeating garbage display) give you a clue whether the SPI is working? Is the 'ungraceful' (infinite loop) failure mode consistent with any path in your program, or I'm really in the weeds (ex: stack corruption)? The fact the error is consistent and my PropGCC program works would seem to rule out some issues. If you think the SPI is still a suspect can you suggest a simple test program (ex: RAM test Txbuffer).
Thanks again!
1.
Initialize W5200
Getting network paramters
Requesting IP.....1$&?@HAI I
Anyway, if it doesn't appear in awhile I'll retry...
First, thanks for your wonderful support for everyone Mike,
definitely above and beyond the call of duty!
Let's start with DhcpDemo, you can see display below. It seems to kind of work. I thought error was perfectly
repeatable, but sometimes bytes to read & amount of buffer displayed varies. But always ends up with infinite repeating
garbage display (as does TCPClientSocketDemoDhcpDns).
I should mention this Prop+Wiz820io setup has been working with a PropGCC program I wrote (my own SPI driver). I changed the pin
definition in my program to match yours and the PropGCC program is still working.
I was wondering about nRESET and PWDN (which I control in my PropGCC program) but my program works without them too (i.e. PWDN=GND,
nRESET floating).
With possible SPI issues in mind I did try a) slowing down the clock (pll8x) and b) using spi.spin, same result just slower.
Does the progress made by the program seem to indicate the SPI is basically working? Is there any path in your program
that would account for the infinite garbage loop, or I'm really in the weeds (ex: stack corruption or ?).
Could you suggest a simple way I can do a SPI test (ex: RAM test W5200 Txbuffer) exercising your code
to rule out SPI issues?
Thanks again Mike!
Initialize
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
0000 01 01 06 33 DA 32 26 00 00 00 00 00 00 00 00 00
0010 00 00 00 00 00 00 00 00 00 00 00 00 00 08 DC 16
0020 F8 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00E0 00 00 00 00 00 00 00 00 00 00 00 00 63 82 53 63
00F0 35 01 01 32 04 0A 00 00 24 37 04 01 03 06 2A 0C
0100 0C 50 72 6F 70 4E 65 74 5F 35 32 30 30 FF 00 00
0110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0150 00 00 00 00 00 00 00
Start: 157 Len: 342
Send Bytes: 342
Open
Send Message
Bytes to Read: 256
UPD Header:
0.0.0.0
3
0
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
0000 00
Start: 165 Len: 0
Bytes to Read: 0
Done
Disconnect
0.0.1.55
-2
I was able to reproduce the error by firing the Discover packet to 0.0.0.0 port 67. From there I better handled unexpected or no return packets.
Please give the DhcpDemo a try and let me know if it works any better.
http://forums.parallax.com/showthread.php?142166-Trouble-getting-W5200-connected-HELPPPPP-newbie&p=1123195&viewfull=1#post1123195
Coincidentally DynamoBen just released W5200 Driver Demo 2.1 so I thought I'd use that to test. I had some problems but got it working. Still not totally clear, but seems possibly interrelated issues of power/hard/soft RESET, fixed/cached/colliding/mismatched MAC&IP settings confusing router, or? Right now I've got your DhcpDemo working, but seems like that's only if I comment out the wiz.SetIP statement? Sorry this is so vague, I'll need to study further before I can contribute anything useful.
For the moment why don't we move on to TCPSocketClientDemoDhcpDns. After commenting out the wizSetIP stmt it runs reliably...up to a point. DHCP response seems good and I checked DNS resolved IP seems OK, but guess then it got stuck in the loop waiting for sock.Connected. Is this a clue, perhaps related, some kind of 'address' issues?
Initialize W5200
Getting network paramters
Requesting IP.....10.0.0.25
DNS...............10.0.0.1
DHCP Server.......10.0.0.1
Router IP.........10.0.0.1
Resolve domain IP
74.125.224.134
Initialize
Begin Client Web request
Open
Connect
What was the IP set to with wiz.SetIP? Was it within the subnet?
Try wiz.SetIp(0, 0, 0, 0)
This can also happen if port forwarding is on. The same port is used in the W5200 setup but the IP changed due to DHCP. The port did not change but the IP did.
Set the port argument to -1 to auto-increment the port number. The port parameter is static and starts at 10,000.
Did you grab the latest code? I created a few validation checks that will report errors with the DHCP conversation.
What port are you using?
Be careful with this line of code remoteIP := dns.GetResolvedIp(1) This will grab the second DNS IP. If a second IP does not exist then the connection will hang.
I confess I'm not following you on possible port forwarding issue. My Netgear router has port forwarding and port triggering radio buttons, one has to be on. But there are no 'services' (port mappings) defined for either. Thought port forwarding took incoming from WAN and mapped to LAN? My PropGCC program can access webpages like finance.google.com. so I don't think it's due to router or ISP? With that program, the source ip port doesn't seem to matter at all, can be anything.
Thanks for bearing with me Mike.
I could be 0.0.0.0 works because the default 192.168.1.107 is not a valid IP on the network.
I really appreciate the testing help! We'll figure it out eventually.
For now here is the latest code. The unit test code can be incomplete.
Google code repository. This is where you can find all updated code.
Resolve domain IP // find google IP
PrintIP(remoteIP): 74.125.224.32 // this is google IP
PrintIP(wiz.GetRemoteIP(0)): 0.180.196.4 // this IP is ???
I'll try to do a much better job of documenting bugs on the code repository. Also I'm adding more validation and error messages so we can get better insight to what's happening.
pst.str(string("Initialize", CR))
buffer := sock.Init(0, TCP, 8080)
sock.RemoteIp(byte[remoteIP][0], byte[remoteIP][1], byte[remoteIP][2], byte[remoteIP][3])
pst.str(string("PrintIP(wiz.GetRemoteIP(0)): "))
PrintIp(wiz.GetRemoteIP(0))
sock.RemoteIp(74,125,224,34)
pst.str(string("PrintIP(wiz.GetRemoteIP(0)): "))
PrintIp(wiz.GetRemoteIP(0))
pst.char(CR)
sock.RemotePort(80)
...and when it runs...
Initialize
PrintIP(wiz.GetRemoteIP(0)): 0.180.196.4
PrintIP(wiz.GetRemoteIP(0)): 0.180.196.4
I would have thought that after 'sock.RemoteIp(74,125,224,34)' that 'PrintIp(wiz.GetRemoteIP(0))' would display '74.125.224.34'? Anyway, if the remote IP is really the mystery 0.180.196.4 that would explain why it can't connect.
PS: I'm having trouble to download the newest code...
http://propeller-w5200-driver.googlecode.com/svn/trunk/propeller-w5200-driver-read-only
...gets page not found.
Sorry to be such a bother Mike, thanks for your support!
This is the home page of the code repository
http://code.google.com/p/propeller-w5200-driver/
If you can get there then click the "Source" tab followed by the browse sub-tab.
If you can't get there then I must have to configure Google code to allow all anonymous users.
http://code.google.com/p/propeller-w5200-driver/source/checkout
...it shows an http: link for anonymous download. But if I type (it's not clickable) it in (with or without the 'blank' near the end of URL) I get page not found. I can't recall having complicatons last time I downloaded (nor exactly how I did it :=)
'return @workspace' did make a big improvement. And I remembered a headscratcher I'd solved before: writes to the W5200 DestinationIP registers aren't reflected until the subsequent CONNECT command is issued...
Initialize W5200
*** wiz.GetRemoteIP(0) after wiz.Init: 74.125.224.78
10.0.0.146
10.0.0.1
10.0.0.1
10.0.0.1
*** remoteIP from DNS: 74.125.224.67
*** wiz.GetRemoteIP(0) after sock.RemoteIP(remoteIP): 74.125.224.78
*** wiz.GetRemoteIP(0)) after sock.Init: 74.125.224.78
*** wiz.GetRemoteIP(0)) after OPEN: 74.125.224.78
*** wiz.GetRemoteIP(0)) after CONNECT: 74.125.224.67
...but nevertheless TSCDDD still can't connect and GET the webpage - can't catch a break :=)
I went back to TSCDD (i.e. with DNS, without DHCP) to confirm that it does work i.e. can connect and GET the webpage. While there I noticed the hardwired DNS server address...
dns.SetDnsServerIp(68, 105, 28, 12)
...so just for kicks I copied that into TSCDDD to use the hardwired DNS server instead of the one returned by DHCP. But if I do that...
Initialize W5200
*** wiz.GetRemoteIP(0) after wiz.Init: 74.125.224.37
10.0.0.146
10.0.0.1
10.0.0.1
10.0.0.1
*** remoteIP from DNS: 0.180.196.4
*** wiz.GetRemoteIP(0) after sock.RemoteIP(remoteIP): 74.125.224.37
*** wiz.GetRemoteIP(0)) after sock.Init: 74.125.224.37
*** wiz.GetRemoteIP(0)) after OPEN: 74.125.224.37
*** wiz.GetRemoteIP(0)) after CONNECT: 0.180.196.4
...lo and behold there's the mystery ip again! And it still can't actually connect and GET. I just confirmed the hardwired DNS (68, 105, 28, 12)works fine in TSCDD (i.e. returns a proper google ip address). So why does (68, 105, 28, 12) return the mystery IP in TSCDDD? Just feels like DHCP and DNS work individually, but somehow aren't playing nice with each other in the demo. I'll keep poking at it, probably turn out to be something simple.
Wireshark is cool but I guess I'd have to setup my PC as a webserver (or use port forwarding?) to really see what's going on. I was able to see the DHCP broadcasts and also (by hardwiring destIP to my PC instead of google) see that the W5200 is attempting to connect i.e. sends SYN until timeout.
I'll try to get the updated code and test more, thanks for your support Mike.
Well, 68, 105, 28, 12 my ISP's DNS server. I probably did an injustice by defaulting network parameters. With that said, I set the default DNS to 0.0.0.0 but it stills works in my environment.
This weekend I'll add demos that show how to set the network parameters. I'll also take a look a the exception handlers and add more serial debug output so we can better identify issues.
The point I was trying to make about using your ISP DNS server (68.105.28.12) was, while it worked (i.e. returns proper address for google) with some of the simpler demos, it returns an odd address in the problematic one (TSCDDD) - and that odd address (0.180.196.4) had been seen before the 'return @workspace' fix - maybe a clue.
*** remoteIP from DNS: 0.180.196.4
I'll monitor the forum, get updated code and keep working at it.
Thanks for your support Mike.
This week end I'll tighten up the code and add more error traps. This should help identify the code block causing the problem in your environment. Most likely I'll need you to supply a dump of the packets received.
If TcpSocketClientDemoDhcpDns.spin does not contain the following code block in Main then you do not have the latest version.
Plus I removed the default values form the W5200, DNS, and DHCP objects. The demos were also updated accordingly.