Atmega8 and enc28J60 for ethernet support

It's not my first time working on microcontrollers and Ethernet interfaces, last time I've used an Arduino board with Ethernet shield for a voice control application. Now I have to build everything from scratch, and the target microcontroller is an atmega8, so the little program memory must be considered. Here is how to use Atmega8 and enc28j60 together for an Ethernet capable application.

Progress summary:
2012-07-30, First setup, using a buffer
2012-10-11, A simpler variant with no buffers
2012-11-03, Another simple webserver

July 30, 2012

My Atmega8 will use an external crystal, and run at 16MHz. It is connected to a 5V supply. The enc28J60 requires 3.3V. The two chips must communicate using the SPI interface.

I found the original project posted on tuxgraphics . The solution is a good starting point, but it has lots of issues like: no buffering between the microcontroller and the Ethernet chip, microcontroller takes CLK signals from the Ethernet chip, not being able to run at various values, not a chance at 16MHz as I need it.

There are numerous reports of issues caused by the voltage difference in the SPI link. I have decided to use a buffer, as indicated by Mirek, from Poland, here. He also sells ready made Ethernet boards that are extremely well built and will save you considerable time for such a project.

The buffer chip is SN74LS125A. For the Ethernet chip I purchased a simple board from Ebay, featuring the enc28J60 chip, the 25MHz crystal, the magnetic ethernet connector, and a few other components:

When the 3.3V are applied and the network cable is connected, the two leds green and yellow should turn on from time to time. I bought two, and both refused to show any led activity. The boards were dead. Looking carefully I've noticed the crystals are soldered improperly and were shorting a few paths of the circuit. Correcting this, solved the problem and the boards were ready for use.
Here is the circuit diagram for these boards:

The connector exposes CLKOUT, INT, WOL, SO, SI, SCK, CS, RESET, VCC and GND. I'm currently using only INT,SO,SI,SCK,CS, VCC and GND. The board takes 3.3V so make sure you use a regulator.

Here is how to connect the Ethernet board to the SN74LS125AN buffer. Only INT and SO need to be buffered:

Now you are ready to connect it to the Atmega8. SO goes to MISO, SI to MOSI, SCK to SCK, I have connected CS to PB2(SS/OC1B) and INT to PD2 (INT0).

The software

The software I've prepared for this article, comes with a minimalistic TCP/IP stack supporting IP, ARP, UDP and TCP, based on the original work of Guido Socher and released under GPL V2 license.
I made it as a simple webserver, to open TCP port 80, so you can connect with your browser but you need to provide a few parameters: http://microcontroller_ip/?cmd=1 . In my sample I've used , but you'll need to change the code for a new IP that matches your network settings.

The firmware replies to PINGs which are counted and displayed on the LCD and on the Atmega webpage. The webpage shows the number of times it has been accessed.

Source code:

Update: October 11, 2012

For a simpler variant, you can skip the buffer and just connect the ENC28J60 module directly to the Atmega8. It will work well, especially if you don't have other devices connected via SPI.

Here is the software to get this running. It comes as a small WEBSERVER, configured as in code, and supports a DS18B20 temperature sensor connected to the PC4 pin, as well as a DHT-11 temperature and humidity sensor, to show the temperature via the web interface:
The problem is the ENC28J60's mini TCP/IP stack uses a lot of the Atmega8's available flash memory. Aprox.6-7K out of 8K available. This leaves very little room for additional logic.

More on temperature sensors here.

Update: November 03, 2012

Here is the very basic webserver implementation, featuring only the Ethernet interface, and the minimum software, that runs a local webserver. IP is configured as, so take that into account when building your own.
Circuit diagram:

I tested this on my testboard, nothing fancy:

It works great, here are some images with pings and the web page it exposes:

The code is available here:

Jan 05, 2015 update: Jarda sent me a variant for compiled for atmega128 designed in Atmel Studio 6.2 + ASF. Code attached: ATxMega128D3_ETH_example

Related Post

This article has 150 Comments

  1. Thanks for sharing! You saved me a lot of time: I’ve got exactly the same enc28j60 board from ebay and I was going to make it work with atmega8 too!

  2. Great tutorial!, I am trying to interface the same ethernet board with an Atmega 32, I have been trying to use tuxgraphics code with some modifications and finally yesterday I got it to ping something. I was looking at your code and got avr studio to build it without any problems! I want to try it later today with my project. Anyhow, I wanted to ask you if your code does display something in the LCD? because I wasn’t able to find the LCD files to look at, if not can you please tell me where am I supposed to write the piece of code for the LCD to display the ping count and all that info?
    I hope you can give me a hand! I have spent a lot of time lost with the ethernet board lol.. and I only have like a month to get my project working!
    Thanks a lot!

  3. Hi Sofia,

    Glad it helped, I myself had endless issues with the enc28j60, including porting the code from atmega8 to atmega168. A suggestion you might already be aware of, it is best to use the PB2 pin for the enc28j60’s CS!

    The first part of my article above already comes with a LCD enabled enc28j60 sample for the Atmega8. HEre is the direct link:

    Let me know how it goes!

  4. Thanks for your prompt response!… I was trying the second code you provided that’s why I didn’t find anything about the LCD sorry lol my bad!..
    After trying the first code, I got it to work but only when I connected the ethernet module and a PC together with an ethernet cable. The problem I get is that when I try to connect the ethernet module directly to the internet and try to ping or access the webserver from another computer in the same network I don’t see any response.
    I was wondering if there is any way to maybe change the subnet mask in the code for the enc28j60? I was told that they need to have the same subnet mask for the communication to succeed. ‘
    Can you tell me how are you intefacing the ethernet module to the internet? I mean do you have the ethernet module directly to the router?

  5. hi Sofia,
    I have to admit I didn’t find a proper way to structure my articles so I can show both the original results and the new updates in an efficient way. Sorry for the confusion with the two versions.
    My enc28j60 is connected directly to the router with a normal, non-crossover , cable.

    You may also want to have a look here:

    What exactly do you mean by ” I try to connect the ethernet module directly to the internet ” and ” access the webserver from another computer in the same network” ? I’m not sure I understand the way your devices are connected.

    Is your enc28j60 using a static public IP? This is rare nowadays. I don’t think you’ll need to change the subnet mask, but instead make sure that both your enc28j60 and the work computer are in the same network, eg. both connected to the same Switch, and that your IPs are in the same class. Note that my code uses, that might need to be changed in your case.

  6. Yay!! I tried it in my house internet and now is working :).. it seems like at my university they have something that was blocking it from sending or receiving any packets.. but here it worked perfectly!

    Thank you very much for all your help! now I can advance to the next step in my project lol

  7. In this configuration, is it possible to burn the Atmega via ISP? In the tuxgraphics version, I have had some problem with it. I think, it was because the 3,3V of the Atmega.

  8. Hey, really good work. Running fine on mine, now i’m just looking how to put a button or other stuff to control leds, etc… Do you have an idea ?

  9. Yes, I found this :

    and it works well but I don’t know how to take the result of the action…

  10. Oh… Sorry I can’t show the HTML code, but i’m able to make a button, but I don’t know how to know if it’s pressed or not…

  11. how connect the atmega 8535 with ems ethernet module? please help me…
    i always error to ping my ethernet module..
    and how many chrystal in atmega8535 for connect to ethernet module? i use 16000000hz but not run, where i use 4000000hz can run. please help me

  12. Hello.
    You are good 🙂
    I have 2 question:
    1 – How can I create a Telnet server with it ?
    2 – How can I create a UDP or HTTP client and send data into Internet (set Default Gateway for ENC28J60) ?

    I’m Sorry ! MY English language is very bad !


  13. Hi,

    1- you will need to implement a telnet server software, running on port tcp/ip 23. it is not very difficult
    2- see my uradmonitor project

  14. Hello, Radu!

    Just noticed your email in this read me file. Sorry to say, I can’t leave any comments on your website. However I left an offtipic comment to one of your youtube videos.
    The questions are if I need to use external crystal? what should be the fuses for atmega8? will your code (the networking part of it) be working without sensors connected.
    I built the second option (no buffer) on the breadboard and it doesn’t work. How do I know (without oscilloscope) where is the fault?

    with kind regards,

  15. Hi Sergey,

    I didn’t try it without external crystal, but I would say you should use one.

    The fuse settings for 16Mhz crystal are:
    avrdude -p atmega8 -c USBasp -U lfuse:w:0xff:m -U hfuse:w:0xc9:m

    So if you are not using Avrdude which is part of winavr, you can simply use the values: Fuse low:0xff , Fuse high:0xC9

    The code will NOT work without the DS18B20 sensor, because there is a loop in the code where it waits for the sensor.

    What exactly do you need? I might be able to put a new code snippet for you.

    Please try to use the comments section, so others can benefit of our little chat.


  16. okay, so many questions!
    should it be working with ds1820, not ds18b20?
    Just tried it, and it does not 🙁 how many temperature sensors does it support?
    BTW, which software do you use to compile that project on a mac (i’d like to change it to 192.168.1. subnet)
    There are just four wires between mega8 and enc, right? miso/mosi/sck/cs
    For some reason it doesn’t work. To make sure my ethernet module is alive, Im going to flash the code from the third update now)

  17. umh, the code from the last option doesn’t work 🙁
    Is there anything else I should pay attention to?
    what are the fuses for the last code? L:xFF, H:0xC9?
    what are the ethernet settings on the PC? (speed, half/full-duplex, flow control, MTU size?)
    probably, the ethernet module is dead…

  18. yep, the two leds are blinking from time to time. well, the green one is turned on, while the yellow one starts blinking actively at first and then it does blink from time to time.
    the new device doesn’t respond to broadcast ping (
    I tried tcpdump, for the first few pings to I get the yellow led blinks and first five records in tcpdump:
    21:46:46.957875 ARP, Request who-has tell, length 28
    21:46:47.958502 ARP, Request who-has tell, length 28
    21:46:48.959448 ARP, Request who-has tell, length 28
    21:46:49.960614 ARP, Request who-has tell, length 28
    21:46:50.961805 ARP, Request who-has tell, length 28
    then the led stops blinking and tcpdump becomes silent. just five times. however, when I do broadcast ping, with each ping I get yellow led blink.
    it turns out I can observe this five time blinking in respond to any pings but for broadcast, which continues blinking always.

  19. I would like to ask you for help.
    Can you pls. upload a program without the loop for the sensors, only showing a simple welcome html page? I have some trouble with getting running the hardware, and related to your reply #23, it should be because of missing sensors.
    Thanky you.

  20. @Libra, I double checked the code attached at the end of the article. It doesn’t make any sensor readings although it contains that particular code. So what is attached there (webserver_atmega8) is a simple webserver, showing a welcome html and the number of pings. Don’t forget the IP is set to , so make sure your network is configured correctly.

    @Serjio: any progress?

  21. Can you pls. check, what chip revision are you using? What is the value of the RBIAS resistor at your eth. module?
    I am just reading the datasheet documentating the revision of the ENC28J60 chips, and I see, that the first two revisions need 2.7KOhm resistor for RBIAS, and the last 2 need only 2.32KOhm resistor.
    I have bought my ENC modules 2-3 months ago and the chips on it were made around the 3Q/2012. At evening, I will check, if my eth. module is in corespondence with the datasheet. I think, it should be the problem of Serjio, too.

  22. Hi, Radu!
    This is great project!

    But I have some problems with that.
    I try to use AVR Studio 5.1 with this project (my AVR Studio 4 don’t want to open project).
    First, what I do – i am changing device to ATMega32, than i check SPI interface (pins for MOSI,MISO,SCK,SS) in net/enc28j60.c.
    CS pin is connected to PC5.
    #define ENC28J60_CONTROL_DDR DDRB
    #define ENC28J60_CONTROL_SO PORTB6
    #define ENC28J60_CONTROL_SI PORTB5
    #define ENC28J60_CONTROL_SCK PORTB7
    // CS pin – atmega8 takes ANY pin, atmega168 will only work with PB2
    #define ENC28J60_CS_PORT PORTC
    #define ENC28J60_CS_DDR DDRC
    #define ENC28J60_CS_PIN PORTC5
    Than I program the microcontroller.
    and at least try to connect this module to my laptop with ethernet-cable.
    Green LED is turned on, yellow turn on/off from time to time.
    Windows XP detect, that it was something connected and tries to send packages, many pakages sent, but nothing returns.
    I also tied to ping ip adress (cmd says “request timed out”) or open it in browser, but it not works.

    where is a mistake? by the way, why atmega168 will only work with PB2?

    p.s. sorry for my english

  23. @libra my boards have a 2.7KO resistor connected to PIN 14 (RBIAS)

    @pavel make sure you try all the three samples posted on this article.

  24. Salut , am nevoie de un sfat din partea ta , am facut montaj cu atmega32 si enc28j60 .montajul functioneaza corect si accesat din alta parte dar problema apare cand placa nu este accesata un timp indelungat (de seara pana dimineata de ex)in momentul cand dau ping dimineata catre ip-ul placii enc nu primesc nici un raspuns… resetez montajul si totul functioneaza normal
    Care ar fi explicatia?

  25. I have absolutely no idea, why it is not working.
    Yesterday I tried to read out the revision number of the enc chip, but I’ve got “0”. I think, the SPI is not working, but I do not know, why (same connection, as yours, Atmgea8A, same fuses, 16MHz crystal, connected only SI, SO, SCK and CS.).
    The last circuit diagram with the minimalistic connection – is there everything, what I need to get it working? Reset and INT is not connected?
    Today evening I will try it out at a solderless board. If no success, you can find some ENC28J60 and Atmega chips under my windows 😉

    Every of the three codes works on the last circuit?

  26. @Libra, good to see you keep your sense of humor, despite these annoying issues 🙂

    I remember I had some issues with two of the blue enc boards I got from ebay. The solution was to re-solder the 25MHz crystals, as the original soldering was improperly executed.

    Can you send me a picture with your setup? MAybe this gives me some additional ideas that might help.

  27. @Florin, salut. Am patit si eu astfel de probleme, dar nu mi-am dat seama ce le cauzeaza. Acum folosesc in uRADMOnitor un Atmega328 care nu se mai blocheaza. Atmega8 se bloca destul de des. S-ar putea sa fie ceva legat de o alocare de memorie, dar nu am identificat exact probelma.

  28. hi ,
    i am doing project on avr embedded web server(atmega32 n enc28j60)…ping to avr ip is working fine but i m unable to access the wepage…pc s connected to wifi…i have connected crossover cable b/n my pc and avr board(intranet)…my pc has ip and i hv set avr ip to…ping to works fine with 4 responses…but when i hit on browser webpage s not coming…pls help me ASAP…its urgent

    avr embedded server Board bought from embedded market

  29. @shrnvs: the code provided here should be use with the circuit presented. for other boards, you should make the adjustments, or contact the vendor of that board for the code.

  30. they provided code on the website…avr net v1.1 in avr…i am not getting where i am wrong…is that code problem or hardware problem…i am unable to ping or access the webpage

  31. yeah i am aware of that…the board wt i hav bought designed based on the general web server by…so board is pre loaded with the avr net v1.1 code…its displaying avr ip and server ip….i connected crossover cable b/n my pc n the board…when i ping the avr ip adress its giving “destination host unreachable “…although green light s on and red light is blinking constantlly…even tried with different pc and straight cable…can anyone find wts the problem…by seeing the code n board probided in this website

  32. Hello, great job pal.

    I’d like to know if you could use LM35 or other analog sensors to the board.

  33. Hi Radu
    i have same problem as pavel. please help us
    i am using atmega32a also i tried PB2 but not worked.

  34. hi
    this is so good program
    i test it and worked fine

    i need display computer ip in lcd on miciro

    how can i get computer ip in avr ????

    i’m waiting for your reply
    please help me
    tank you

  35. Hi. No need to cross link. Instead you must make sure your IP is correct: either in the microcontroller or in your LAN configuration.

  36. @javi AVR Studio
    @Raha I didn’t try but with the proper modifications you should get it going in Eclipse too.

  37. Thanks for the reply! I also wanted to know what exactly you mean when you say that “the mac and ip have to be unique in your local area network. You can not have the same numbers in two devices”??? Are you referring to the IP address of the mac here??

  38. Estimated thank you very much, but I’ve been trying to open it in 6.1 without being able to study atmel … if you can not specify the program vercion please …

  39. This is of minor importance, but because you asked, I am currently using Atmel Studio 6.0

  40. Hello,
    we tried the “very basic webserver implementation” code with an atmega8 (atmega8-16pu) wired up exactly like in the above schematic. It didn’t work. After a while we figured out that it works fine if CS of the ethernet module is connected to PB2 (SS) pin of the atmega8, like you suggested in the code for atmega168 devices. Pin number has to be changed in the file /net/enc28j60.c

    Some Routers additionally have problems with MAC addresses which don’t start with 0x00

    Thank you for the great project!

  41. I am trying to do very basic server from your last post but i have problem with that. Are you sure that the INT and RESET isn’t connected? Shouldn’t it pull up? I changed in your code mac address (first hex 0x00, not 0xCD) and ip address (, not and compiled it. I connected my device to router and when i write to my browser or ping it I have no respond. Can you send me please hex file with this IP and MAC to test it. Maybe i am doing something wrong…

  42. @wojciradom: I have used exactly what the article shows. But some routers require a valid MAC address, in this case try using something like: static uint8_t mymac[6] = {0x3C,0x07,0x54,0x52,0x1B,0x17};
    The rest should work unless you did something wrong.

  43. Ok, thank you, i will try today. And what about CS pin? Should i connect it to PC5 or PB2? Please, send me on my email your hex with this change (IP & MAC) if you can, because I have some problem with my AVR Studio (i have some warning, that atmega8 is not supported with something, i cant remember now). I want to be sure that software is ok. Thank you a lot for help!

  44. Can’t get it to work on my ATMega8-16PU :(..
    Wired it up exactly as the scheme above (the most basic one) but couldn’t get it to work.

    Didn’t changed anything in the program.

  45. Hey radu, i’ve implemented your project with atmega128 and showed exactly like your screenshoot in my chrome.

    but now i want to build another project as a client, my purpose is to chat with simply server aplication (not web browser) in my PC and i confused with code do i need to change because in your project that you share the atmega is a server not a client.



  46. Hello Radu
    I am trying to realize this project and it doesn’t work. Everything is wired like on the scheme. I have no idea how should I fix it… There is really weird problem with SPI. In enc28j60WriteOp this code works:
    SPDR = op | (address & ADDR_MASK);
    But after setting SPDR = data, there starts infinite cycle at waitspi();
    Can you help me? Is it just my stupidity? THX a lot

  47. Hi
    How can I create a UDP or HTTP client and send data into Internet (set Default Gateway for ENC28J60) ?
    You ask
    see my uradmonitor project

    but i not found source code uradmonitor project!!!
    how to do? or where to download?

  48. hi Banec. Currently the uRADMonitor source code is not available, because I plan to release it as a commercial product.

  49. Maybe lay out some of the code from set Default Gateway for ENC28J60?
    Please update the code webserver_atmega8.
    Thanks in advance.

  50. Sorry for bad English.
    I need a default Gateway.
    IP, MASK, GW.
    access via the router from another subnet.
    Please update the source code webserver_atmega8 and add ip default Gateway.

  51. Hi radu. thanks for sharing this project. [atmega8 webserver]
    i have some problems with this project that i thought you could help me.

    First, i can’t ping and i can’t get the webpage from browser and also arp command don’t show this device. I’m add some printf to some sections of the code to get an insight view of the code. I’m start to pinging this device, i get this message: destination host unreachable. but when i print the “buf” buffer, there are some data in it like this:

    108 240 73 180 120 73 205 21 22 23 24 25 8 6 0 1
    8 0 6 4 0 2 205 21 22 23 24 25 192 168 1 120
    108 240 73 180 120 73 192 168 1 100 0 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

    i implement this code on an ATMEGA128.
    What is your idea?

  52. Hi Ali, it’s hard to put a diagnostic from what you’ve posted, my advise is to double check your circuit, this is not a critical one so if you made it correctly it should work right away.

  53. Я могу читать по-русски тоже. Извините за не в состоянии помочь вам.

  54. Может вы не хотите внести изменения? а не можете?
    Выше вы писали что внесли изменения в код uRADMonitor.
    т.е. библиотека enc28j60.c(h) должна быть совместима.
    проще говоря, вам нужно перенести два файла из проекта uRADMonitor в проект webserver_atmega8!!!
    Вы же автор? или нет?

  55. Помогая другим, на этом блоге мой подарок для сообщества, а не обязанность. Я уже говорил вам, что не имеют код, который нужно, и не имеют время, чтобы исследовать эту проблему. Как я уже сказал, извините за не в состоянии помочь вам в дальнейшем.

  56. Hi.
    The problem was in the hardware. now it is working. of course i was a little late for reporting this. sorry for that.
    anyway, i add some other sections to the web server, and write a complete html for it. now it is working like a control panel.
    I add some other url except the main url. the device’s main screen [specifications and some logos] are in the main url [] and the sensors are in the ‘s’ url [].
    by adding an auto-refresh meta tag to the sensors html code [] the page will refresh automatically, so it looks more like a monitoring panel.
    in other effort i will use buttons in html page to configure my device, by using POST method.

    I have a question: what you’ve done to the code, so it will work with 16MHz AVRs?
    and thanks for this code.

  57. Hi Ali,

    With my circuit you are free to use any type of crystal you want. I used similar circuits with both 8MHz and 16Mhz crystals with good results.

    Feel free to post your control panel project code, if you feel like helping others that might need to do a similar thing.

    Best wishes,

  58. Hi, Radu!!
    Its all works really great. Thanks a lot.
    But I would like to do such uC Device, that can be swithed throuth internet.
    Idea is – uC will be connect to Internet via ENC28J60. Than user can switch something via internet from another side of Earth.

    My quastion is – how can that will be done? How can I bind my uC-webserver with certain domain, for example ??
    Thank you.

  59. А как сделать отправку информации с АТмеги на ПК без запроса определенной веб страницы?

  60. Народ Буржуйский и Славянский, помогите! Собрал хренатень, за программеровал в итоге желтый свет морг-морг? в чём лажа

  61. @zigler: Если вы не нуждаетесь в сервер, вы можете использовать сокеты или любые другие средства связи.

    @jurec: жаль друг, я не понимаю, что вы хотите

  62. да собрал, а работать не хочет! есть, “под рукой”,
    простая прошивка, чтоб пинг был в локалной сети?

  63. Dear

    I am trying to do a project using atmega16,8MHZ and ENC28j60 Module. I have tried with success…what should i do to implement a TCPclient using Atmega 16 running on 8MHZ and ENC28J60 module. Please help i am stuck :(.

    I am using AVRSTUDIO 5.0 on WINXP. I dont have any hardware help (i cant change 8MHz to 16 MHz)

    please revert asap.

    Thanks and Regards,

  64. Можно ли вместо веб.сервера реализовать веб.клиент для сети интернет? Т.е. чтобы была зозможность отправлять информацию на обычный apache web-сервер с помощбью метода GET ?

  65. На сайте реализован и вебсервер и вебклиент. Я пробовал вебклиент (версию 5.3) товарища Guido Socher, с платой как для Вашего вебсервера. Пока ничего не заработало. Подскажите, пожалуйста, какие значимые отличия платы товарища Guido Socher от нашего ENC28J60 module и вообще, какие могут быть отличия и трудности?

  66. hi Radu,

    I am waiting for your valuable reply. how to start with your code for ATmega 16,8 MHz. I even dont have LCD…where should i send the string if worked successfully…


  67. Hello Radu,

    I am trying to run “basic webserver implementation” on an atmega8L-8pu and I want to know if I am taking the correct steps when programing the micro-controller.

    1. Burn the fuse bits for the 16Mhz Crystal

    avrdude -p atmega8 -c USBasp -U lfuse:w:0xff:m -U hfuse:w:0xc9:m

    2. Download the code “webserver_atmega8”:

    I)Change the IP to my range (considering that my PC has IP
    II)rebuild the source and obtain a new hex

    (Should I also change CS to PB2 ?)

    3. Write the hex to the Atmega with avrdude.

    4. Put the atmega on the board, CS is conected to PC5, power it up and try to ping it. (The sensors are not connected on the board just the simple schematic)

    The problme is that there is no response to ping. What am I missing ?


  68. Hi Radu,
    variable myip and mymac are represents to ip and mac of atmega8? or represents to ip and mac of my computer?

  69. Hi Galih,

    For the mega8, you need to connect CS to PB2. I already explained this in the article.

  70. Hi man,

    I am trying this,

    I compile it with avr gcc (fine). But when i run it i can’t ping it / acces it on webbrowser the router also don’t detect the device.

    I have put a “real” Mac adress and the good IP :

    static uint8_t mymac[6] = {0x00,0x1f,0x16,0xaa,0x5d,0x9b};
    static uint8_t myip[4] = {192,168,1,40};

    Actualy i am debuging it by puting some “BEEP();” on the code for listen where it go or not.
    Actualy it go on the while(1) fine !

    I am continuing debugging for know where it have a problem. .

    My circuit is on a PCB, the SPI is working fine (before it was on a testlab SPI was not working because of wires, but now maybe the “SPI” is “ok”)

    If someone as any idea ..
    Me i continue debugging

  71. I precise just about the BEEP() (lol)

    it’s a simple function for active a buzzer for make “Beeps”

    void BEEP(void)
    PORTB |=(1<<0);
    PORTB &=~(1<<0);

  72. That i don’t understand, the code is working well .. it turns in the While(1)

    But i can’t ping my device, can’t acces to the webbrowser TCP server […]

    for me the card doesn’t have the IP configured or something like that (my router doesn’t see the device, and playing with nmap i does not find it..)

    The led’s on the ethernet module, are working, the green alway’s ON, and yellow is ‘ON’ when i transmit something on the network from my computer;

  73. Actualy it stay at “dat_p=packetloop_arp_icmp_tcp(buf,enc28j60PacketReceive(BUFFER_SIZE, buf));” but web serveur is not started and i can’t ping it,

  74. I do a mistake* Actualy it’s working well in the code (enter in the while(1) infinites times, maybe i need to see before, why server isn’t started.. Did we have to configure something else than IP / mac ?

  75. Oh my god guy’s …

    Now it works fine, pings & website …
    I have change the MAC ADRESS by something else (my computer mac adress +1 at the last part)

    So now i want to understand … Did the enc28j60 cab be set only for a “range” of mac adress ?
    Or what did make the problem ? Did the router have a list of “know” mac adress ?

  76. Cyber, it’s not the ENC28J60, but your router that probably didn’t allow the previous MAC you’ve used.

  77. When I compile the codes will show this error
    “Error: D:\cvavr2\inc\pgmspace.h(90), included from: ip_arp_udp_tcp.h: incomplete type is not allowed”

    And by clicking on the above line of code error file “pgmspace.” h “indicates this line
    “typedef void prog_void PROGMEM;”

  78. Hello Radu,
    I tested the basic webserver implementation code with enc28j60 interfaced with atxmega microcontroller. Its working fine. Now a step ahead, I am testing another program in which I want to transfer the number fed by user on webpage (using submit button on web) to microcontroller and then again display the fed number on webpage. The code line is as below:
    plen=fill_tcp_data_p(buf,plen,PSTR(” EnterNumber: “));

    With this I am not able to get entered number into the variable Numbber(unsigned int). Always I am getting 0 for Numbber which is its initial value. Where I am making mistake? Please help.

  79. Hello Radu,
    I tested the basic webserver implementation code with enc28j60 interfaced with atxmega microcontroller. Its working fine. Now a step ahead, I am testing another program in which I want to transfer the number fed by user on webpage (using submit button on web) to microcontroller and then again display the fed number on webpage. The code line is as below:
    plen=fill_tcp_data_p(buf,plen,PSTR(” EnterNumber: “));

    With this I am not able to get entered number into the variable Numbber(unsigned int). Always I am getting 0 for Numbber which is its initial value. Where I am making mistake? Please help. It seems in my earlier post complete code didn’t came.

  80. Hi Radu,
    I was able to port the basic ATMmega8 Web server codes into ATMega32 AVR with a slight modification at port pins and it is fully functional.
    Thank you very much for sharing your know how with others..

  81. Dear Radu,
    I came to your webpage containing the web server project with ATmega8 while I was working with the ENC28J60 module. I have tested your sample web server (the version without the buffer), then converted the code to C and found it working without any problem. It is true that the ATmega8 has very limited resources (only 1KB SRAM and 8KB Flash). However, I want to fully utilize the flash memory for storing webpages consisting of HTML and CSS. But apparently, the server cannot reply large webpages with size bigger than the size of the buffer (defined as BUFFER_SIZE in code).
    Can you shed some light on it? (i.e. How to send large webpages using the small buffer, probably by fragmenting ?

    Another thing that would be really helpful if it was possible to simulate the web server in the Proteus or other simulation softwares. Did you try?

    With Thanks,

  82. !!!!!!!! PLZ HELP
    Hi Radu i tried to compile this code by atmel studio. it’s compiled and and i programed it on my micro (low fuse bits: FF high fuse bits : d9). but when i try to ping it on my system (my local lan statics ip is : i got error.

    can every one help me ?

  83. Hi!

    One question regarding sensor readings:
    Why are aou doing it in ISR? Can it be moved to main/while routine?
    Does variables for reading dht11 and ds18b20 need to be globals?

    Your ISR lasts pretty long, measure time for both those sensors is >1s.


  84. hello sir,
    Thanks for your publication of Atmega8 with 28J60 interface.
    I have interfaced Atmega32A with 28j60 module and it work successfully as i has used network switch using normal straight wire.It is responding
    very well for PING request.
    I want to implement it as client to open TCP/IP socket on some port number say (example 8000).
    can you help me in this regard.

  85. hello sir,
    Thanks for your publication of Atmega8 with 28J60 interface.
    I have interfaced Atmega32A with 28j60 module and it work successfully as i has used network switch using normal straight wire.It is responding
    very well for PING request.
    I want to implement it as client to open TCP/IP socket on some port number say (example 8000).
    can you help me in this regard.

  86. Dear Redu,
    thank you for perfect example. I port your web server example for newer chip ATxMega in new Atmel studio 6.2 with ASF. If you want, i can sent to you example project to publish on this web.
    Just reply for my email.
    Best regards, Jarda, Czech

  87. Great Project, Put together very well. I’ve been trying this for a few weeks now and I have a series of doubts that i would like to ask you,
    1. Is there any way I can simulate ENC28J60 in Proteus ISIS?
    2. Can I use the “ATmega8_ENC28J60_NOBUFFER_TEMP_WEBSERVER” project to communicate over the internet, or is it limited only to the ethernet?
    3. And where can I get an explanation for the TCP/IP stack that is implemented for the in the file “ip_arp_udp_tcp”, cause I wanna learn the concepts behind it.

  88. I am using ATMEGA88 instead of the one you have used and with a 20MHz external clock, I have compiled the code and got the following warnings:
    Warning 4 unused variable ‘plen’ [-Wunused-variable]
    Warning 3 unused variable ‘dat_p’ [-Wunused-variable]
    Warning 1 “F_CPU” redefined [enabled by default]
    Also, I cannot ping the module, I am using cross over cable directly to my laptop, do you have any suggestions?

  89. Hi I am trying to do a similar project with the Atmega8515, will this code work with the Atmega8515?
    I tried your code webserver_atmega8 and I am still unable to ping the enc28j60 from my PC.
    -I am using the LD1117v33 voltage regulator to get my 3.3v for the enc28j60
    -I connected the enc28j60 with MCU using SS to CS, MOSI to SI, MISO to SO and SCK to SCK.
    -changed the port# configuration for SS, MOSI, MISO and SCK in your enc28j60.c code
    Can you tell me what I’m missing?

  90. Привет У меня работает но медленно.идет несколько ping и ping не идет.я не использовал буфер. чём проблема?
    можете сказать как поставит fuse bits.

  91. Hi I have a few runs but medlenno.idet ping and ping can not idet.ya not use the buffer. What’s the problem?
    can tell how to put the fuse bits.

  92. Dear Radu, thanks for sharing such great work. you have made it very simple.

    I am trying to make your basic “webserver_atmega8” code work on “AtMega32” and need a bit of help.
    Modifications i have made are:
    # connected CS_PIN –> PORTB4 (SS)
    # MCU running at internal 8Mhz: changed F_CPU to 8000000UL
    # changed ip address to my laptop’s range (using a cross-over cable to connect the ENC module to the laptop directly)
    # network adapter in the laptop shows that it is connected to an unidentified network.
    # Green led on the module turns ON and remains ON
    # Yellow led flickers, seems as if there is some communication going on
    On pinging: no response, only yellow light flickers when pinging is active.
    On Wireshark the laptop’s network adapter is constantly sending ARP packets but no response comes from the module.

    Any hint from you would be highly appreciated. Thanks.

  93. Hi Varun,

    It’s hard to tell, but I’d try to hook it to a router just to see if there is any change in the ARP traffic. Nevertheless keep us posted on your progress. The CS Pin is ok (the PB2 is required for the atmega8 mostly), and so is the 8MHz frequency (I use this more as well).

  94. hello Radu,
    thanks for replying. that turned out to be a power supply problem. it is working fine now on atmega32.

    in my project i need a data logger device which will periodically update the server with the data. I have same functionality working with a WIZNET module which is very easy to work with as it has a hardwired TCP-IP stack.

    How do I use this (webserver_atmega8) library to achieve following:

    1. open a TCP connection
    2. send an HTTP packet containing data to the server
    3. receive the response (HTTP packet) from the server
    4. close the connection

    on Wiznet my HTTP packet looks like this:
    sprintf(data, “GET /hm/index.jsp?id=%lu&value=%u HTTP/1.1\r\nHost:\r\n\r\n”, id, value );

  95. Is there a sequence of command/reads that would indicate if the ENC28J60 is running and ready?

    The RJ45 jack shows the green light on, and the orange light blinks whenever the connected pc tries to ping it or request a web page from it. However, it always times out (the micro never sees the request)… So not sure if it’s the host not configured correctly (crossover cable, static ip) or if it’s the micro software (tcp/ip stack, static ip, spi) or if it’s the jumper wires (spi, power) going to the ENC module.

    With the logic analyzer, the SPI communication seems reasonable, that is, nCS goes low followed by 8 SCLKS (1Mhz), and then the expected transmitted data that the micro sends. The ENC does often respond with non-zero data. The SPI mode is 0 (CPOL=CPHA=0 ; Data sampled on Rising edge).

    This is the spi activity to/from the enc28j60 module
    Out In
    FFh 00h
    FFh 00h
    BFh 00h
    03h 00h
    9Fh 00h
    00h 00h
    48h 00h
    00h 00h
    49h 00h
    00h 00h
    4Ch 00h
    00h 00h
    4Dh 00h
    00h 00h
    4Ah 00h
    FFh 00h
    4Bh 40h
    07h 00h
    4Ch 40h
    FFh 00h
    4Dh 40h
    07h 04h
    BFh 00h
    03h 02h
    9Fh 80h
    01h 01h
    58h 50h
    B1h A0h
    48h 48h
    3Fh 38h
    49h 49h
    30h 30h
    50h 50h
    F9h C0h
    51h 51h
    F7h E0h
    BFh A0h
    03h 03h
    9Fh 90h
    02h 02h
    40h 40h
    0Dh 0Dh
    41h 41h
    00h 00h
    82h 82h
    32h 32h
    46h 46h
    12h 12h
    47h 47h
    0Ch 0Ch
    44h 44h
    12h 12h
    4Ah 4Ah
    DCh D8h

    Any suggestions how to see if the enc28j60 chip is working properly?

  96. Hello,

    I´ve trouble with your solution. I connected all as your pictures show. I burned firmware to my ATMega8a with little changes (ip-> and F_CPU -> 8MHz), but i cant ping it. System show 0 recieved packets, I´m connected directly to computer. Network adapter have this settings: static ip ->,mask Please help me, I´ve recheck all 100000x but i cant see any problem.

  97. hello,..
    if I could ask for a program code?
    I just wanted to learn microcontroller that can be connected to the internet.

  98. Dear Radu,

    thanks a lot for your reply. Why PB2? Im using PC5 as CS port. Im testing your solution without buffer from 3rd november 2012. I think that problem is in comunication between MCU and ENC mini board, because computer sends packets to enc and enc recieved them (orange led is blinking) but there is no response from enc. I connected it exactly like your circuit diagram shows. I changed only F_CPU to 8000000UL and atmega is using internal clock 8 MHz. Is there any chance to check if mcu and enc comunicate correctly? Thanks for your time

  99. Thanks Radu,

    I´ve tested it with other atmega8 and 16MHz crystal and it doesnt work. Maybe enc mini board is faulty (I dont think so, but it is possible). I will buy another module from ebay and test it.

  100. I’m traying to recompile the code, on Linux/Debian Jessie, and have problem witch Makefile:
    GMD.d:1: *** multiple target patterns. Stop.
    Any ideas?

  101. Hi would this setup work with an ATMEGA328P-UP programming using USBASP and Atmel Studio 7. Am new to this type of programming current status is have an LED blinking 😉

Leave a Reply