Shop OBEX P1 Docs P2 Docs Learn Events
W5200 RJ45 cable detection — Parallax Forums

W5200 RJ45 cable detection

oodesoodes Posts: 131
edited 2015-07-02 13:56 in Accessories
Is there any way to detect if a Ethernet cable is plugged into the RJ45 connector in software on the W5200? I want to find out if after i have already established a connection if the cable has been removed so as to flag up an error. After I established the socket and connect and send data, if I remove the cable and I call the method 
sock.connected
or
sock.getStatus
it returns the same value as when the cable is connected

Comments

  • PHYSTATUS register at $0035 bit 5 indicates link up but there isn't any interrupt that I know of for it so you will just have to poll this I guess.
  • PHYSTATUS register at $0035 bit 5 


    Where can I find this? 
  • What do you mean? You have read the manual I take it and all I did was search for "link status". But I'm not a very good mind reader so unless you communicate effectively I won't be able to help you much.

  • Sorry I didn't mean where in the manual can I find this. I'm using Mike Gebhard's W5200 driver and I wanted to know how to access Bit 5 of the PHYSTATUS register so I can poll the link status. 
    I should use :
    PRI ReadByte(PSTATUS)   spi.Read(register, 1, @workSpace)  return workSpace[0] & $FF
    ???
  • PUB GetPSTATUS                            'Method in W500 object   return ReadByte(PSTATUS) 
    PUB GetPSTATUS                           'Method in Socket object    return wiz.GetPSTATUS
    pst.bin(Sock.GetPSTATUS,8)           'Method call in Top Object

    With the Ethernet cable connected  or disconnected , all I ever get is '00000000' outputted on the PST
    From the Image attached I should be getting a '1' at bit 5 when cable connected right?


    619 x 439 - 43K
  • I use my own software so I can't really help you with that object but the cable detect relies upon sensing a signal, not the cable itself, which means it needs to be plugged into a hub or something on the other end.
  • It is connected to a network switch at the other end , so there is a signal (when connected :D ) . I can close the socket , and try to open it again which will tell me if the cable is connected or not but that would be more cumbersome approach
  • Well all I can tell you is that this register works correctly, I report it as "link up".

  • Ok, sure thanks anyway.
  • I happened across this thread since I am having some internet connectivity issues with my own W5200. In case you haven't figured out how to get access to the PHY status byte I shared my SPIN code below. I also needed to change the ReadByte procedure in the W5200 object (wiz. in my code below) from PRI to PUB so my code could get access.

    I just tried it and sure enough bit 5 is set when the cable is connected to my router and not set if there is no connection. There must be connectivity (of some kind) with the router because just having a unconnected cable inserted in the connector results in a 0 bit.

    I hope this helps.
    
    ' Read and display the physical status byte on the W5200
      iTemp := wiz.ReadByte( $35 )
      pst.str(string( 13, "W5200 PHY status register: %"))
      pst.bin( iTemp, 8 )
    
      IF iTemp & %00100000 > 0
        pst.str(string( " Link is UP."))
      ELSE
        pst.str(string( " Link is DOWN.")) 
    
    
  • Thanks for the code snippet , I'll give it a try . I could never manage to get a 1 at bit 5 with a disconnected cable.
    I ended up closing the connection and re-opening as a cable check which is a bit cumbersome. I'm away on holidays but ill give it a go when I get back and let you know if it works.

    Appreciate the help MJ

    Des
  • Tried this today and it worked.
    Cheers MJ ,
Sign In or Register to comment.