Shop OBEX P1 Docs P2 Docs Learn Events
Just got a WIZNET 812MJ — Parallax Forums

Just got a WIZNET 812MJ

average joeaverage joe Posts: 795
edited 2013-01-25 19:02 in Accessories
Started with the demo@ http://spinneret.servebeer.com:5000/

Looking at the Spinneret Web Server code, I'm trying to figure out what to do about the RTC since I have none. I've though about using one of the RTC emulators or possibly just disable them? Any advice from the experts would be greatly appreciated.

Also plan on using in SPI mode. I see that the driver is not directly compatable with Indirect Addressing object??

Comments

  • Mike GMike G Posts: 2,702
    edited 2013-01-04 10:06
    Average joe, you can find minimal and base code (does not have the RTC) on Google code for the Spinneret project. This uses an indirect driver.

    The new stuff, which I suggest, is also located in Google code

    Checkout the Html5Graph.spin, that's a pretty good demo. Really, the only things you need to do is make sure the IO (hardware/software) is configured correctly or as expected.

    Also, the later does not require an RTC. However, in both cases, if using the FAT engine, the RTC driver can be turned off in the FatEngineWrapper by entering a -1 for the I2C arguments in the start method.
  • Don MDon M Posts: 1,652
    edited 2013-01-04 16:30
    Mike G wrote: »
    The new stuff, which I suggest, is also located in Google code

    Checkout the Html5Graph.spin, that's a pretty good demo.

    Mike- I checked out this site but don't find anything to download.
  • Mike GMike G Posts: 2,702
    edited 2013-01-04 17:28
    Don, you have to click on of the file names. Then click the "Raw File" link on the right. It's a bit of a pain if you're not using SVN.
  • Don MDon M Posts: 1,652
    edited 2013-01-04 17:39
    I was looking at it with IE and don't see the files. I clicked on it through Chrome and now I see the files. You must have to be logged into Google in order to see the files? Anyway I see them now...
  • Mike GMike G Posts: 2,702
    edited 2013-01-04 18:12
    You must have to be logged into Google in order to see the files?
    No...
  • average joeaverage joe Posts: 795
    edited 2013-01-04 23:12
    Thanks guys! I think I've got it working now. The latest google code was most helpful! Just changed some pin numbers and I'm off.
    I'll have a bunch more questions soon, still need to play with this a bit more.

    Huge thanks for the quick response guys :D
  • average joeaverage joe Posts: 795
    edited 2013-01-24 23:49
    I had things running on the "expansion" board and attempted to ditch the expansion and connect the WizNet directly to the "touchburger". Not as simple a task as I'd hoped. The touchburger shares all (20) pins in "groups" (4). So I connected the Wiznet using 2 or gates *for /SCS and /Reset*. I was hoping all I would need to do with code is stop and restart the SPI cog when using the pins for other groups. But it seems like the spi driver doesn't like this?
    'from w5100
    PUB Suspend
        spi.Stop
    
    PUB Restore
         spi.resumeCog
    
    'from spi cog
    PUB Start(p_cs, p_sck, p_mosi, p_miso)
      if not cog
        'Init Parameters
        _cmd    :=  1
        'Pin assignments
        _sck  :=  p_sck 
        _mosi :=  p_mosi
        _miso :=  p_miso  
        _cs   :=  p_cs
    
        Cog := cognew(@startSpi, @_cmd) + 1
        repeat while _cmd
        result := cog
      
    PUB resumeCog
      if not cog
        _cmd    :=  1
        Cog := cognew(@startSpi, @_cmd) + 1
        repeat while _cmd
        result := cog
    

    I also added code to start cog if not running
    PUB Write(addr, numberOfBytes, source)
    
      ' validate
      if (numberOfBytes => 1)
    
        IF NOT cog
          resumeCog
      
        'wait for the command to complete
        repeat until _cmd == 0
    ..
    ..
    PUB Read(addr, numberOfBytes, dest_buffer_ptr) | _index, _data, _spi_word
    
      ' test for anything to read?
      if (numberOfBytes => 1)
        IF NOT cog
          resumeCog
    
        repeat until _cmd == 0
    ..
    ..
    

    The top level code, port of dnsDemo
    PUB Init | ptr, url, ansRRS, i,d
    
      tch.beginDesktop("S")                                        ' warmBoot
      font := tch.Loadfont(string("4x6.ifn"))                 ' black on white 16 point, load and set font to file
      tch.SetOrientation(false)
      tch.Clearscreen(tch.GetBackFontColor)                        ' clear screen to BackFontColor = font file loaded above
      tch.SetCurx(0)                                               ' return Cursor to X 0
      tch.SetCury(0)                                               ' return Cursor to Y 0
    
      buffPtr := @buff
      ansRRS := 0
    
      tch.SelectMemGroup
      tch.TextT(font,string("Initialize"))
      tch.crlf
      tch.SelectSPIGroup
         
       'wiz.QS_Init
      wiz.HardReset(WIZ#WIZ_RESET)
      wiz.Start(WIZ#SPI_CS, WIZ#SPI_SCK, WIZ#SPI_MOSI, WIZ#SPI_MISO) 
       
      'Loop until we get the W5200 version
      'This let us know that the W5200 is ready to go
      repeat until d := (wiz.GetVersion > 0)
        pause(250)
        if(i++ > ATTEMPTS*5)
          DebugStr(string("W5200 SPI communication failed!"))
          return     
      wiz.HardReset(RESET_PIN)
      
      wiz.SetIp(10, 10, 10, 107)
      wiz.SetMac($0F, $08, $DC, $16, $F8, $01)
      sock.Init(0, UDP, 53)
      sock.RemoteIp(10,10,10,1)
      sock.RemotePort(53)
      debugStr(string("version "))
      debugHex(d,8)
      tch.crlf
      
      url := @url5
      
      repeat
        CreateTransactionId($FFFF)
        FillTransactionID
        
        bytemove(@urlBuff, url, strsize(url))
        byte[strsize(url)] := 0
        debugStr(string("URL: "))
        debugStr(@urlBuff)
        tch.crlf
        
        'Copy header to the buffer
        bytemove(buffPtr, @msgId, DNS_HEADER_LEN)
        'Format and copy the url
        ptr := ParseUrl(@urlBuff, buffPtr+DNS_HEADER_LEN)
        'Add the QTYPE and QCLASS
        bytemove(ptr, @QTYPE, 4)
        ptr += 4
         
        DisplayMemory(buffPtr, ptr - buffPtr, true)
        ptr := SendReceive(buffPtr, ptr - buffPtr+1)
         
        GetRcode(ptr)
        debugDec(rcode)
        debugStr(string(": "))
        debugStr(RCodeError)
        tch.crlf
         
        if(rcode == 0)
          ansRRS := ParseDnsResponse(ptr) 
         
        repeat i from 0 to ansRRS-1
          ifnot(GetResolvedIp(i) == NULL)
            debugStr(string("ip_"))
            debugDec(i)
            debugChar($20)
            PrintIP(GetResolvedIp(i))
            tch.crlf
        pause(2000)
         
    PUB debugStr(strptr)
      wiz.Suspend    
      tch.SelectMemGroup
      tch.TextT(font,strptr)
      tch.SelectSPIGroup
      wiz.restore
      
    PUB debugChar(char)
      wiz.Suspend
      tch.SelectMemGroup
      tch.SetCurx(tch.textChar(font,char,tch.GetCurX,tch.GetCurY))
      tch.SelectSPIGroup
      wiz.restore
      
    PUB debugDec(value)     |  x ,i
      wiz.Suspend
      tch.SelectMemGroup
    {{Send value as decimal characters.
      Parameter:
        value - byte, word, or long value to send as decimal characters.}}
    
      x := value == NEGX                                                            'Check for max negative
      if value < 0
        value := ||(value+x)                                                        'If negative, make positive; adjust for max negative
         tch.SetCurx(tch.textChar(font,"-",tch.GetCurX,tch.GetCurY) )               'and output sign
    
      i := 1_000_000_000                                                            'Initialize divisor
    
      repeat 10                                                                     'Loop for 10 digits
        if value => i                                                               
          tch.SetCurx(tch.textChar(font,(value / i + "0" + x*(i == 1)),tch.GetCurX,tch.GetCurY))                                        'If non-zero digit, output digit; adjust for max negative
          value //= i                                                               'and digit from value
          result~~                                                                  'flag non-zero found
        elseif result or i == 1
          tch.SetCurx(tch.textChar(font,"0",tch.GetCurX,tch.GetCurY))                                                                 'If zero digit (or only digit) output it
        i /= 10                                                                     'Update divisor
    
      tch.SelectSPIGroup
      wiz.restore
      
        
    PUB debugHex(value, digits)
      wiz.Suspend
      tch.SelectMemGroup 
      {{ Send value as hexadecimal characters up to digits in length.
      ''
      '' `Parameters:
      ''
      ''     `value: byte, word, or long value to send as hexadecimal characters.
      ''     `digits: number of hexadecimal digits to send.  Will be zero padded if necessary.
      ''
      '' `Return: none.
      ''
      '' `Example: pst.Hex(1234, 5)
      ''
      ''     Output decimal 1234 as five hex digits. Outputs `004D2.
      ''     Next lines, if needed...
      }}
    
      if (digits > 8)
        repeat digits - 8
          tch.SetCurx(tch.textChar(font,"0",tch.GetCurX,tch.GetCurY))
        digits := 8
      else
        value <<= (8 - digits) << 2
      repeat digits
        tch.SetCurx(tch.textChar(font,(lookupz((value <-= 4) & $F : "0".."9", "A".."F")),tch.GetCurX,tch.GetCurY))
    
      tch.SelectSPIGroup
      wiz.restore
    
    Everything else is stock. Any thoughts would be greatly appreciated as always!
  • Mike GMike G Posts: 2,702
    edited 2013-01-25 19:02
    I believe you are looking for something like this...

    Spi5100CounterPasm.Spin
    PUB Start(p_cs, p_sck, p_mosi, p_miso)
    
      'Init Parameters
      _cmd    :=  0
      
      'Pin assignments
      _sck  :=  p_sck 
      _mosi :=  p_mosi
      _miso :=  p_miso  
      _cs   :=  p_cs
    
      cog := cognew(@startSpi, @_cmd) + 1
    
    PUB Stop
      if cog
        cogstop(Cog~ - 1)
      
    PUB ReStart
      cog := cognew(@startSpi, @_cmd) + 1
      
    PUB Write(addr, numberOfBytes, source)
    
      ifnot(cog)
        ReStart  
    
      ' validate
      if (numberOfBytes => 1)
    
        'wait for the command to complete
        repeat until _cmd == 0
    
        _iobuff := source
        _len := numberOfBytes
    
        _cmd := ($F0 << 24) + (addr << 8) + byte[source]
    
        repeat until _cmd == 0
    
        ' return bytes written
        return( numberOfBytes )
    
      else
        ' catch error
        return 0 
    
    
    
    PUB Read(addr, numberOfBytes, dest_buffer_ptr) | _index, _data, _spi_word
    
      ifnot(cog)
        ReStart
        
      ' test for anything to read?
      if (numberOfBytes => 1)
    
        repeat until _cmd == 0
        
        _iobuff := dest_buffer_ptr
        _len := numberOfBytes
        
        _cmd := ($0F << 24) + (addr << 8) + 0
        
        repeat until _cmd == 0 
    
        ' return bytes read
        return( numberOfBytes )
      else
        ' catch error
        return 0 
    

    W5100.spin
    PUB ReStart
      spi.ReStart
    
    PUB Stop
      spi.Stop
    

    I'm not a fan of ReStart logic in Read and Write Methods. It works but I'd rather explicitly invoke Start and ReStart.

    I'm not sure about the OR gate mentioned. Please post a schematic.

    A hardware reset can take up to 1.5 seconds to take affect. Registers R/W will function while socket commands may not. That's been my experience.

    Google code has been updated with the latest. The socket library and W5100 can better handle large file downloads. I did not add the ReStart logic to Google code.
Sign In or Register to comment.