[SOLVED !] ENC28J60 , a simplistic driver


Closed Thread
Page 1 of 8 123 ... LastLast
Results 1 to 15 of 109

Thread: ENC28J60 , a simplistic driver4889 days old

  1. #1
    _Gabi_
    Guest _Gabi_'s Avatar

    0 Not allowed!

    Default ENC28J60 , a simplistic driver

    Hi,

    Reading those nearly abandoned threads (btw no activity there for about 2 months ?????):

    http://www.picbasic.org/forum/showthread.php?t=5787 or
    http://www.picbasic.org/forum/showthread.php?t=5416

    I was thinking to give a hand on developing code for the "so popular" nowadays ENC28J60 ethernet chip, for anyone that might need it.

    So here you have a very basic ENC28J60 driver (merely a hand typing saver), as per Microchip DS39662B - ENC28J60 datasheet, for half-duplex mode.

    It is provided just to start you up and hopefully you will see that it is not so hard to do it in Proton, provided that you carefully read the device datasheet and you have a basic ethernet and tcp/ip knowledge.

    Ofcourse you have to further develop your own protocols (i.e. arp, icmp, udp, tcp,....ethernet packet parser, buffer handling routines,,,, etc) for having some working application.

    I have tried to comment the code as much as I have seen it fit, so it could be followed thru ENC28J60 datasheet.

    Where the code will reference other documents like RFC's, those will be pointed out in comments.

    Attached file is released under MIT license (i.e. http://www.opensource.org/licenses/mit-license.php ), therefore there is NO support on this driver version.


    My special thanks goes to Tim on starting me up with this ethernet chip

    HTH

Attention

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #2
    LittlePIC
    Guest LittlePIC's Avatar

    0 Not allowed!

    Default Good to Hear a reply!

    To Gabi,

    Good to hear a reply!(Mine was the second thread...) almost 12 months ago!

    I was suprised at the lack of responses at the time but amazed at the hits - seemed at the time there was some interest in this subject but no replys other than Lester...

    I Like your inc file - I managed somthing similar - to get the registers mapped and run some basic sub routines using SHIN SHOUT to prove a working circuit, but went the Microchip C way(after all it was written and only needed to be ammended to suit my needs...)Project was completed on time and worked...

    Since then,I've changed jobs, spare time is almost non existant and no longer work in design but would be happy to help out writting some routines using your inc as a start again...would be good to get 'free' ethernet addition to the Proton Development compiler...

    What were you thinking of to start?maybe a arp (i.e ping response) then move to UDP , PPP then the grand daddy TCP/IP...well baby steps first...

    Will keep you posted on my developments...

    regards

    LittlePIC

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #3
    _Gabi_
    Guest _Gabi_'s Avatar

    0 Not allowed!

    Default

    Hi,

    right, we all need "time".

    FYI I have already done my tcp/ip protocols, though not open source. This is just a driver, so you have to write at least arp+icmp+udp to have a communication application. Anyway, if I can I will help.

    For those who want to try, here is attached a working example for the ENC28J60 driver, using about all SPI functions, and could be a short and quick test for your test board, as it will initialize the nic then set LEDA to flash quickly and LEDB to display the Link Status and Rx/Tx activity on Link. Also there is an example on how to read a PHY register.

    Please use the ENC28J60.inc file (included in this attachement) and scrap the previous one.

    HTH

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #4
    andyoz
    Guest andyoz's Avatar

    0 Not allowed!

    Default working with 16f877

    Hi,
    I realise this thread is probably dead, or else maybe no-one wants to give
    away any secrets! :-)

    But i thought i'd post my observations about this driver.

    It's been quite interesting, (thank you for posting this Gabi), i *was* starting to
    write my own, but not being that good a programmer, i was finding it tough
    going, so this has been very helpful thank you.

    There have been two changes i had to make to get it going on a '877

    Both changes in the ENC28J60.inc file, first change was from:
    >>;* PIC MSSP Register settings
    >>;
    >>SSPCON1 = $20 ; Enable SPI,idle Low,Fosc/4
    >>SSPSTAT = $40 ; transmit On rising edge,sample middle

    To:
    >>;* PIC MSSP Register settings
    >>;
    >>SSPCON = $20 ;for 16f SSPCON1 = $20 for 18f ;Enable SPI,idle Low, Fosc/4
    >>SSPSTAT = $40 ; transmit On rising edge, sample middle

    Because the '877 doesn't have a reg called SSPCON1, only SSPCON, simple change.

    Second change was more perplexing, i still don't understand why the original didn't work, but my change certainly does work.

    The SPI_SUB: originally contained:
    >>SPI_SUB:
    >> btfss SSPSTAT.0 ; Has data been received(transmit complete)?
    >> bra $ - 2 '

    I changed it to:
    >>SPI_SUB:
    >> While SSPSTAT.0 = 0: Wend

    And it works fine.

    Only thing i could possibly guess is because i'm actually still on Proton+ v2.1.5.3

    But that doesn't make much sense either.

    Now i've just to start transmitting some packets, i'd really like to get dhcp, arp, and icmp going.
    Final task we'll be to send snmp queries, and read the returns (this is my ultimate goal for the little project i have in mind).

    Hopefully these notes help someone else, if they're having trouble like i did.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #5
    _Gabi_
    Guest _Gabi_'s Avatar

    1 Not allowed!

    Default ENC28J60 - driver , Proton+ compiler UDP demo code

    Hi,

    in my view, the number one trouble that a potential pic coder may have while trying to connect to different hw chips is that he does not read the data sheets, or he try then gets scared of it.

    Anyway, here is a UDP demo code to be used with the ENC28J60 ethernet chip.


    Hardware:

    The ENC28J60 board is connected to the PIC device used (ie here the 18F458) as you can see in schematic and declares section.

    Note: that if your PIC is running at 5V then you will need level shifters on the lines going out from ENC28J60 to PIC. There are various ways to do that, so I do not go into that.



    Network connections:

    The ENC28J60 board is connected to a network card in PC, via a crossed cable, as the firmware is only intended for this type of connection. Minimum extra code lines will be needed to connect the board to routers and such.



    What it does:

    The board was thought as a UDP server only, that will reply to incoming requests using UDP transport.

    That is, it will check if the destination IP is that of this board and the protocol used is UDP, however, it does not check for a specific UDP port (ie will accept any port number), then if those match will send back to the sender a message (as defined in UDP_REPLY_SUB subroutine in ENC28J60_Driver.Inc).

    You can also find in that sub, that we check against the UDP payload, (that is, we expect an "F" or "G" character, but could be any type of variable), and we act upon the received payload.

    You can easily change things (ie code) in this sub, to check for any other commands that you may implement in your application.

    Also, the board will reply to incoming ARP and ICMP requests addressed to it.


    User defined constants:

    You should edit the following constants to suit your hw/sw settings:

    1.) In the ENC28J60_Driver.Inc
    - ENC28J60 Hardware connection To Host Controller , ie the hardware connections to your PIC controller;
    - HARDWARE (MAC) ADDRESS DEFINITION , that is the MAC of your ENC28J60 hardware board;
    - SOFTWARE (IP) ADDRESS DEFINITION , which is the IP address that you assign to your ENC28J60 hardware board;

    Note: your board IP should match the class of PC network card that is connected to.


    Testing the board and firmware:

    Programs like Ethereal (http://www.ethereal.com/) should be used to debug the packets sent or received by the board, if that is needed.

    You can Ping the board directly from Windows console.

    To test the UDP (and not only), you can use a nice piece of free software from: http://www.hw-group.com/products/hercules/index_en.html.


    Recommended:

    Please read the ENC28J60 data sheet including erratas to your device revision to fully understand what and how the chip does, and also, you might find it helpful to read those RFC's involved, for the protocols that you may want to
    use at: http://www.rfc-editor.org/



    Hope that there are no more mysteries around writing code for this chip in PDS.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #6
    mechatron_
    Guest mechatron_'s Avatar

    0 Not allowed!

    Default

    thanks Gabi...

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #7
    andyoz
    Guest andyoz's Avatar

    0 Not allowed!

    Smile

    Ditto on the thanks Gabi!

    I've had a quick glance at your driver, and i can see you've done a LOT more
    work on it!

    This will make life a hell of a lot easier for myself, and anyone else
    experimenting with these chips.
    You're a far, far better programmer that i am, i'll readily admit!

    I'd basically gotten up to the point where i could reliably receive a packet,
    and i'd written some simple code to display the results, as part of my
    understanding of what was going on. example output:
    Waiting for a packet
    RX_PACKET_TYPE=0800
    IP_PROT=01
    FRAME LENGTH=004E
    ICMP
    ICMP Request
    ICMPSEQ=7806
    ERDPTL=54 ERDPTH=00
    Source IP =192.168.1.2
    Dest IP =192.168.1.5


    (static arp entry on the pc so i could "ping" the enc even though it couldn't
    reply, not even to ARP)

    But that was as far as i'd gotten, i was starting to wrestle with sending a reply, and was looking at the IP Header checksum calculations, which i can
    do on paper, and then figuring out how to code that.
    But you've done that all for me thanks

    A big agree on reading the datasheets, it's become my bible at the moment.
    Read, read, and re-read, reading and comprehending are two different things!

    I got my enc28j60's from digikey a couple of months ago,
    and they're rev B4 parts, so i've been very mindful of the errata, as there's
    a few problems with that rev, which haven't bitten me (yet)
    I've gotten away with-out using level shifters, although i know it's extremely
    borderline doing so.

    I've read elsewhere that if not using level shifters, all it takes to break the ENC to PIC comms is something as simple as the PIC 5v line to be 5.2v

    When i make up a proper pcb, i'll be including level shifters.
    If i actually create something useful from this, i'll be certain to share it.
    Thanks again.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #8
    andyoz
    Guest andyoz's Avatar

    0 Not allowed!

    Default

    Hi Gabi,

    Got one question, what's the usage of POSTINC2 in your driver?
    It doesn't seem to be declared or defined anywhere?
    I'm *guessing* it's supposed to be some sort of pointer into TX_PRE_BUF.
    Would i be right in thinking that?
    It almost looks to me like i should use TX_PRE_BUF[x] (where x is the correct byte number in the packet), instead of POSTINC2, am i on the right track,
    or way off the mark?

    Also a tip for anyone else playing around with the ENC28J60, don't try and do it
    with a 16F877A (only 368 bytes of RAM), like i have.
    Choose a PIC with more RAM for variable storage, Gabi's declared a 18F458
    (1536 of RAM). (which i'll probably end up changing to, or similar)
    The larger RAM allows you to transfer chunks of data via the spi bus using the
    ENC's wbm and rbm commands and keeping a full copy of the packet in local
    RAM, rather than nibbling (byteing??) at it a location at a time, via the spi bus.
    Which will slow things down TREMENDOUSLY, as well as being rather messy.

    Save yourself the headache and use a larger PIC, after all, if you really
    want to play with ethernet, you're not wanting to transfer just a few bytes
    at a time!

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #9
    Fanatical Contributor Tim's Avatar
    Join Date
    Jan 2003
    Posts
    7,682
    Thumbs Up
    Received: 47
    Given: 95
    Total Downloaded
    1.32 GB

    0 Not allowed!

    Default

    POSTINC2 is an ASM directive look in the pic manual to see how it works.

    Yes you can use TX_PRE_BUF[x] its just a little slower that's all (approx 4 x slower maybe even more)
    Tim

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #10
    andyoz
    Guest andyoz's Avatar

    0 Not allowed!

    Default

    Hi Tim,
    Thanks for that, makes a lot more sense now. I downloaded the manual for PDS and found the explanation.
    Unfortunately i'm still on Proton+ V2.1.5.3

    I can't really justify the upgrade to PDS yet, as this is only a hobby
    for me, even though i do qualify for the 99.00 upgrade.
    (I originally purchased the old "Crownhill PICBASIC Plus")
    That works out at approx. 250 Australian dollars.

    I keep hoping there'll be a 'special' at some time, but i know i'll eventually
    have to upgrade anyway.

    So i'll just have to continue on with work-arounds for now, and missing out
    on all the lovely new features in PDS.
    (Of which i know there's quite a lot!)

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #11
    ohararp
    Guest ohararp's Avatar

    0 Not allowed!

    Default

    The 18F4620 is pin compatible with the 16F877A and has ~4k of ram.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #12
    Fanatical Contributor fanie's Avatar
    Join Date
    Oct 2005
    Posts
    7,986
    Thumbs Up
    Received: 31
    Given: 15
    Total Downloaded
    434.52 MB

    0 Not allowed!

    Default

    Hi Gabi,

    I know this probably sounds like a silly question, but what can one do with an ENC28J60 ethernet chip and a pic hooked onto it ? To be honest, I have no clue !
    Fanie

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #13
    _Gabi_
    Guest _Gabi_'s Avatar

    0 Not allowed!

    Default

    Hi Fanie,

    well, its just a simple ethernet chip interface, which make possible connecting various micro controllers (i.e. PICs included) to a LAN or WAN, and described by Microchip as:

    Microchip's ENC28J60 is a 28-pin, 10BASE-T stand alone Ethernet Controller with on board MAC & PHY, 8 Kbytes of Buffer RAM and an SPI serial interface.
    and some of the possible applications includes (though not limited to) :

    VoIP, Industrial Automation, Building Automation, Home Control, Security and Instrumentation

    HTH

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #14
    Don Stratton
    Guest Don Stratton's Avatar

    0 Not allowed!

    Default

    Quote Originally Posted by _Gabi_ View Post
    well, its just a simple ethernet chip interface, which make possible connecting various micro controllers (i.e. PICs included) to a LAN or WAN
    I am aware of these chips, but I am unsure if they have any applicatibility in my projects. My problem is I am not a desktop programmer and don't wish to be, so comm work is always done at the mercy of existing desktop software; serial is easy becvause there are a million tools for it including Hyperterminal and serial loggers, USB was impossible for me until a friend wrote a custom app for me because there is no such thing as a Hyperterm for USB (a generic app that can communicate with diverse hardware with no knowledge of said hardware).

    Is this similar to USB, where only programmers need bother? Or more like serial, where there is a wealth of generic, agnostic apps?


    --Don

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #15
    dmTulsa
    Guest dmTulsa's Avatar

    0 Not allowed!

    Default

    Thank you GABI, the .inc really helps a great deal. I'm building up the ENC28J60 board in the next few days. This is going to be extremely useful for many projects. I'll just be using RAW packets or UDP, there's no need for TCP for most things I do.

    Don,
    If you use most any Basic, VB, PowerBasic, RealBasic ect... they all have "Sockets" functions or controls. Its just as easy to do as RS232 or USB. I'd guess there are generic apps out there but I've never had the need since I write my own. If you need any help in this area feel free to contact me.

    Thanks again Gabi

    Doug

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Closed Thread
    Page 1 of 8 123 ... LastLast

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. [SOLVED !] ENC28J60 Driver
      By Dave-S in forum Proton Plus Compiler v3
      Replies: 1
      Last Post: 7th March 2017, 22:02
    2. ENC28J60 support
      By hadv215 in forum Ethernet Module
      Replies: 1
      Last Post: 15th November 2014, 07:42
    3. ENC28J60 help
      By akvii in forum Ethernet Module
      Replies: 5
      Last Post: 17th May 2013, 21:12
    4. Problem ENC28J60 + 18F452+ driver GABI
      By gerben-88 in forum Proton Plus Compiler v3
      Replies: 1
      Last Post: 14th May 2013, 06:44
    5. SPI to ENC28J60
      By gerben-88 in forum Proton Plus Compiler v3
      Replies: 1
      Last Post: 22nd November 2009, 23:42

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts