ENC28J60 Web server from SD Card

Go To Last Post
24 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have got a web server running quite successfully with a Wiznet W5100 Ethernet chip. It serves files with long filenames on a FAT16 microSD memory card.

I thought that I should try to do the same with ENC28J60 chip and compare performance.

As far as I can see, all existing AVR code originated from Tuxgraphics. Unfortunately, all their examples rely on serving very SMALL web pages. i.e. you can't serve up multiple packets.

Has anyone got this working? I am guessing that many people have had the idea of serving general purpose web pages. I am hoping that it is just a question of setting up the multiple packets correctly. And that someone has already written the code.

Has anyone used a ENC28J60 with the M*crochip TCP/IP stack? Or experienced their demo code?

Incidentally, the W5100 server works pretty well. The idea of having GB of pages served by an Arduino independent of a PC is pretty cool.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I used the ENC28J60 with a mega128, and lwIP which has a webserver example. For the packet driver I used the tuxgraphics one and increased the maximum packet size.

Microchip code can only be used legally on a Microchip processor (except the ENC28J60 driver). What I've heard it's quite good code. Of course, for a private project nobody is going to care that you port the code to an AVR.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Correction. I did not use an AVR, but an Altera NIOSII. Should not make a real difference.

I also used an AVR with the ENC28J60 but used uIP instead which is way more limited that lwIP.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Increasing the TX packet size is not really an option with a mega328P. It is not even an option with a any size SRAM. Any web page > 1500 bytes is going to need multiple packets.

So it looks as if I need to do some studying of the M*crochip code, and adapt the Tuxgraphics stack.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

David, i think uip will probably be the easier and more effective route. I think there's a few projects out there to draw from. I played with lwip on a mega128 once but i cant recall how much code space it took. The tuxgraphics stack is pretty brain dead as it doesnt handle multiple packets.

I think i may have tried this one as some stage:
http://code.google.com/p/avr-uip/

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Kartman,

I had a brief look at M*crochip stack, and it is a nightmare to follow.

I am going out with my dog. If we don't get waylaid in the pub, I will have a look at the uip route.

Ideally, I would like the W5100 structure and API.

Of course, I am only testing it via my local router. I have not even thought about public use, multiple clients etc yet.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

uIP will be slow as it cannot handle multiple outstanding packets, it needs an acknowledgement for each single one before it sends the next. It's not meant for high performance webservers ;)

lwIP is bigger and has more features like DHCP. I don't know whether it would fit a m328, my guess it won't or barely.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

David,

Spent many hours with http://en.klinkerstein.m-faq.de/index.php/MicroWebServer and added some features to it, ie an smtp mail client.

Here's the link https://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=79225&highlight=microwebserver It was a challenge getting it to work, but a good learning experince.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
increased the maximum packet size.

do you mean :

#define BUFFER_SIZE 3092

but it's a small page, if I need bigger html and css file from sd card, how can I rectify it ?
I used the code from tuxgraphic
thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So much less painless to do LAN interface on small micro if you use this:
http://www.saelig.com/MFR00088/B...

All protocols off-loaded to this chip. Only code in the attached microprocessor is a relatively simple socket interface. Big buffers are offloaded too, for both TX and RX.

The Microchip modules are antiques.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You want to use uip (contiki) or lwip then. Google these terms with avr and you'll find some examples.

Seriously, if you want to play around with these things there are better alternatives. Ti have a tiva board with ethernet for $19.95 usd delivered. Mine are coming monday. Or there's mbed which software wise is a nicer solution. The mega128 has only 4k of ram which is not much when you want 512 bytes for a a sdcard buffer, 1500 bytes for ethernet so you're not left with much left. The ti part has 256k ram and 1m flash.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think atmega128 can handle a small page only, that's from my test and not easy for me if I put SD card,
because I separate their CS already, but when I want to test FatFS software while ethernet connected, it can't run, CS already separated, PB0 for SD and PB4 for ENC28J60.....
How about STM32 with 512K flash and 64K SRAM ?

thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The mega128 can serve up a page as large as your sdcard, but it isn't the most efficient solution - especially when there are a number of low cost options.
With the PB0 and PB4 problem, i've given you pointers on how to identify the problem. It is not going to fix itself and you've not given us anywhere near enough information to suggest a fix. We've told you to make PB0 an output otherwise the spi wont work. You have a logic analyser to look at what is happening and still you have no solution.

What stm32 board has ethernet for 19.95 delivered?

The enc28 chip works, but it is a bit dodgy. There are better alteratives.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

How about STM32 with 512K flash and 64K SRAM ?

Your posts amuse me. If you are planning to spend money then why not replace the crappy $2 ENC28J60 with something like:

http://www.shopwiznet.com/wiz200web

Which is a complete Atmega128 based computer with ethernet interface that can do all the high level protocols and that has external flash and RAM for handling large web page data.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have W5100 module, perhaps I can use it ? but how can use external RAM ? any suggestions for external RAM chip for ATMEGA128....
I'm still curious on making MEGA128 running a web server with sdcard....

Probably
http://www.radiolocman.com/shem/schematics.html?di=71093

Do you reckon 32 Kbytes SRAM will be enough for SDcard and ethernet working together? I dug to my chip box and found UT62256 70LL SRAM chip, I got 2 pieces, but I'll use 1 for experiment, it's 32 Kbytes SRAM

or to make it simple I use ATMEGA2561
http://www.atmel.com/devices/ATMEGA2561.aspx

Will 8Kbytes of RAM be enough for SDcard and ethernet...so far I use 3092 for buffer on ethernet...not yet SDcard ?

Thanks for the module suggestion

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

but how can use external RAM ?

Exactly as the 128 datasheet tells you. For an example see the openly published schematic of Wiznet's WIZ200WEB.

As to how much RAM ot add - only you know the size of data you may want to server. While you can work with a RAM buffer that is smaller than the data you want to serve life is likely simpler if the biggest chunk of data will fit into a single buffer. However do bear in mind that the biggest region the 128 (or any AVR with extmem) can address at any one moment is 64K (in fact possibly a little less because of SFRs and internal RAM) so you probably want to keep it at 64K or below unless you are ready to handle paged memory banks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

is it possible, if I want to display 64Kbytes page but I divide it with 1024 buffer ?

so load the buffer for 64 times ? or I must load the buffer at once,
....
in my experiment, the more datas I want to display on firefox, I need to increase buffer (RAM)...

any clues and experiences ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you are really thinking of serving 64KB pages then why constrain yourself to a pissy little 8bit micro? I'll take back what I said above your STM32 idea might be a better one.

In fact there's a solution that probably costs less than any AVR based solution and that is astronomically better. That is to get a Raspberry Pi (or similar) running Linux and install apache2 on it. That is the web server that possibly supports about 25..50% of the entire web (perhaps more?). It is a truly industrial solution. You can put any technologies you like on top (SQL, PHP etc) and you can server any media type of virtually unlimited size.

(I haven't checked but I would be kind of surprised if AVR Freaks you are reading right now was not using apache to host the phpBB software)

This will all cost you $35.

As always - pick the right tool for the job. If you want to get from Paris to Sydney you probably use a jet not a rowing boat!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Clawson, thanks for the enlighment, so it depends on what I want to serve...thanks a lot..

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

BTW just checked it using telnet to make a GET request to Freaks:

HTTP / 1.1 200 OK
Date: Fri, 21 Mar 2014 15:26:59 GMT
Server: Apache
X-Powered-By: PHP/5.1.6
Set-Cookie: POSTNUKESID=o51lia8isqv0a21uerspoq83r6; expires=Fri, 28 Mar 2014 15:27:22 GMT; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: cache
Pragma: no-cache
Content-Length: 30358
Connection: close
Content-Type: text/html; charset=UTF-8

Note the Server: line in there. So, yes, Freaks is running on Apache.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Regardless of what device you use to serve the pages, ethernet has a maximum packet size called the MTU which is around 1536 bytes. So to send a large file, it gets broken up into chunks of the MTU or less. If you have a mega2560 and a wiznet module, i dare say there is Arduino code to do a webpage, possibly with a sdcard. The answer is a Google away.

Also if you're going to play around with ethernet, you'll probably need a tool called 'wireshark'. Download it and you can see the traffic on your ethernet.

This is all a moot point if you don't have the skills to resolve your PB0/4 problem. You're starting to move into more complex territory, so you need to work on your Googling and debugging techniques. The stuff you're doing is not new and the questions have been asked and answered before.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The Wiznet 820io module is the best choice,as all protocols are off-loaded from the microprocessor host, there are up to 8 concurrently active BSD-like sockets as the interface to the host micro via SPI, MTU sized TX and RX buffers for each socket, and so on.

The Microchip module is cheap. But so too is a Renault.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
But so too is a Renault.

I'll bite, what's wrong with Renault? I've owned both Peugeot and Citroën cars. In my experience the French make some really great cars. I've no reason to think that Renault wouldn't be just as good.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What would Jeremy Clarkson say about French cars?