Shop OBEX P1 Docs P2 Docs Learn Events
Wiznet W6100 Spin2 driver usage — Parallax Forums

Wiznet W6100 Spin2 driver usage

Started using the @ke4pjw Spin2 driver for W6100, hoping to use it to implement Modbus TCP for the P2PLC project...

Have it working, sort of...
Using a version where the top file is "SpinnerEdge_Top.spin2".

Thing Terry might have added a regular SPI interface after asking for it. He uses the 8-bit parallel interface.
Have to select which one here:

  ' Init Ethernet
'  elock := W6100.initparallel()
  elock := W6100.initSPI()

Thought the SPI pins in the main file were for the W6100, but these are for uSD. Added a comment there:

CON 'uSD card pin settings
  DOPin = 58
  CLKPin = 61
  DIPin = 59
  CSPin = 60

The actual ethernet SPI pins are in W6100drv.spin2. A bit confusing there because A0 and A1 are actually MOSI and MISO in SPI mode. Added a comment there. So, the pins here changed by comments are the ones you need:

  CLK   = 39'16
  MOD   = 16
  ADDR  = 18 ADDPINS 1
  RSET  = 23
  CSn   = 40'17
  RDn   = 21
  WRn   = 22
'  INTn  = 20  'Not used
  DATA  = 24 ADDPINS 7
  DPINS = 24 / 8
  A0    = 38'18      'mosi in spi
  A1    = 41'19      'miso in spi

There are also some hopefully unused pins defined here and also some LED pins defined below this. Have to make sure these aren't actually being used or disable that...

Using this with the DMB-4775 enclosure board with a special PCB for the SWaP module and a daughter PCB interface for the wiznet module.

I'm directly connecting with ethernet cable to a spare ethernet port on a PC. This doesn't seem to be a DHCP server, so need to specify IP address for the wiznet here:

  ' Set IP Address. Set to 0.0.0.0 for DHCP
  IPADDRESS[0] := 192'0
  IPADDRESS[1] := 168
  IPADDRESS[2] := 1'0'137
  IPADDRESS[3] := 2'150

  ' Set Subnet Mask. Set to 0.0.0.0 for DHCP
  SUBNETMASK[0] := 255
  SUBNETMASK[1] := 255
  SUBNETMASK[2] := 255
  SUBNETMASK[3] := 0

' Set Gateway Address. Set to 0.0.0.0 for DHCP
  GATEWAY[0] := 192
  GATEWAY[1] := 168
  GATEWAY[2] := 1'0'137
  GATEWAY[3] := 1'10'1

' Set DNS Server Address. Set to 0.0.0.0 for DHCP
  DNS[0] := 192'8
  DNS[1] := 168'8
  DNS[2] := 1'8
  DNS[3] := 1'8

Anyway, so after all that (and copying the files in the "SDCARD" to the uSD card, it seems to work, sort of.
It serves up index.html from uSD to browser, but the page appears either blank or with just the text, "Spinnernet Edge". It doesn't seem to serve up the .png background file. Working now to figure this out.

Will probably eventually switch this over to C, where there is another solution, but want to get this working first.

Should also update the uSD driver with the new one from @evanh ...

Comments

  • ke4pjwke4pjw Posts: 1,220

    @Rayman What browser are you using? I may be too aggressively closing the connection on the webserver. I have wanted to change how those timeouts are performed in the driver, now that I know more about how they can be handled. The browsers want to keep a persistent connection open to the webserver, but that prevents anyone else from connecting.

    I am happy to help out with anything I can.

  • ke4pjwke4pjw Posts: 1,220

    Ok, this was a terrible way to add a wait. For the moment, change 10000 to something larger like 25000. I am going to rework this to be a number of ms to wait before closing the connection.

    There are several improvements I have not folded into this terrible code of mine that I have made in other projects.

  • ke4pjwke4pjw Posts: 1,220

    @Rayman Be sure to copy the favicon.ico file too. Otherwise the browser will try and pull it on every request instead of caching it. That may make for unexpected results.

  • RaymanRayman Posts: 15,605

    @ke4pjw Thanks. Adjusted that delay, but doesn't help...
    Wondering if browser doesn't like the index.html file...

    The favicon is showing up on browser tab, not sure how though...

    From the debug it looks like the code is seeing a request with a blank filename...

    DHCP is working btw, testing that here at home...

    520 x 938 - 34K
  • RaymanRayman Posts: 15,605
    edited 2025-09-08 14:09

    @ke4pjw Appears that Edge does not like your html file...
    Made a new one with image and it works...

    896 x 504 - 239K
  • ke4pjwke4pjw Posts: 1,220

    Hey @rayman, based on the debug, it should be setting the filename to index.htm. If the length is 5 characters, it knows it is "GET /". I will move that down to show the parsed filename.

    Maybe there is a problem with the file index.htm file. Make sure it is named index.htm as index.html is not the default document. I should have it configured to go through the list of potential default documents (index.html , index.htm, Default.htm, etc) It should be setting the image file as the background image of the .htm page. That's why I was asking what browser you were using. I had some problems with how Safari and Safari mobile works and have not rolled those changes into the code located at https://griswoldfx.visualstudio.com/spinner edge/_git/Software

    I have spent some time adding comments to the W6100.spin2 file in that repo. I had some additional changes I am going to make, but they will potentially break existing code. Only minor tweeks needed to make existing code work again. I am adding proper timeouts based on ms, rather than a crude arbitrary counter.

  • RaymanRayman Posts: 15,605

    Ok, I'll try again with your index.htm. These are files that this driver came with for testing....

  • RaymanRayman Posts: 15,605
    edited 2025-09-08 17:38

    Ok, it's strange. Sometimes my index with image works and sometimes it doesn't.
    I can see the request for the image in the debug window, but must not be going through...

    This is on a PC with Edge browser. Maybe safari is different?

    On the initial request it doesn't appear to get a filename and just goes with its preset default, "index.htm".

  • RaymanRayman Posts: 15,605

    Think it might be something with the filesystem. Seems like it can only serve up on file and then quits...

  • RaymanRayman Posts: 15,605

    Think found the problem!

    Commenting out the second condition makes it work:
    Repeat until FS.fileTell() == FS.fileSize() 'or W6100.isdisconnected(socket) == True

  • ke4pjwke4pjw Posts: 1,220

    @Rayman I am going to take a look at it this week. It was put there so that very large file downloads could be aborted appropriately.

  • RaymanRayman Posts: 15,605

    Thanks @ke4pjw . There's no rush.
    Maybe top level needs some tweaks but driver seem good.

    One other minor issue: The DHCP fails occasionally. Maybe it can try a few times before giving up?
    App needed for won't use DHCP, so not a big deal for me...

  • ke4pjwke4pjw Posts: 1,220

    @Rayman said:
    One other minor issue: The DHCP fails occasionally. Maybe it can try a few times before giving up?
    App needed for won't use DHCP, so not a big deal for me...

    I have seen that on occasion. Yeah, I think we should have it retry if it doesn't hear a reply in time.

    --Terry

  • ke4pjwke4pjw Posts: 1,220

    I have not published yet, but have updated dhcpclient() so that if it does not receive a response in 5 seconds it tries again. If it makes it's way to the failed status, it calls itself again.

Sign In or Register to comment.