For the past few weeks I’ve been working on developing an AVR based embedded ftp server. Unusually in this case, necessity was genuinely the mother of invention, rather than ideas just sounding cool. I need a server to keep files I’m working on that can be accessed over the internet or my local network. A the moment I have a ten year old blue behemoth of a server which sits digesting huge quantities of power while it waits to serve the odd text file. Clearly what is needed is something smaller. Much, much smaller.
Searching the internet for suitable hardware brought me to the ENC28J60. It is an Ethernet controller, combining a 10BASE-T MAC and PHYceiver on a single chip, with an SPI interface which makes it easy to use with microcontrollers. Searching the internet also brought me a page full of similar devices to the one I was trying to design, which was disheartening. Never search for a new idea on the internet because someone’ll probably have already done it better than you could and be selling them for a few pounds a go. On the other hand, the other devices all appear to be more powerful web servers with a very small amount of storage, as opposed to my tiny 8-bit fileserver with as much storage as you can get on an SD card.
I persevered, and went to the chip shop, where I picked up the ENC28J60, and an ATmega328P. I was dubious about whether an AVR µC would have enough memory to simultaneously juggle a TCP/IP stack, ftp server and FAT filesystem, as well as the SPI interface to the ENC and memory card, so I used the biggest, baddest ATmega in the series. It has 512K of SRAM and 32K of flash memory which should be enough to do all those things with a carefully optimised operating system.
I built this prototype on a solderless breadboard, which is useful both because it is easy to move things around and make changes, and because I am awful at soldering. (Really; if nothing’s on fire by the time I put the iron away I tend to consider it a success). It looks like spaghetti because I’m using bits of bell wire in lieu of proper jumpers.
The ENC runs at 3.3V, and the ATmega can run at anything from 1.8-5.5V, though it can be clocked faster at higher voltages. To keep the component count down I’m using a 3.3V rail for everything, unless there are performance issues with the ATmega when I come to test it.
The ATmega connects to the ENC and an SD card (not on the breadboard in the picture) via SPI. It uses two extra pins for chip selection to enable it to use two slaves with one master buffer.
On the physical output side, the ENC is connected to a magjack, which contains an RJ45 ethernet jack, as well as the magnetics needed to drive it. These consist of an arcane network of transformers designed to isolate the delicate electronics you’ve nurtured into life from whatever terrible things might happen on the other end of the cable, and dampen down interference. I’ve also added a coil/capacitor pair on the transmit line to help block high frequency EMF.
There is no such thing as a through-hole mounted SD card connector, so I can’t use it with any kind of prototyping board. This means I won’t be able to actually test the memory card interface until I’ve already built a PCB and soldered everything down. And if my through hole soldering is clumsy, my surface mount soldering is manifestly cloven hoofed.
Next time I’ll talk about the firmware side of things, also known as “the difficult bit”, which I’m still developing.
Note: I’m using acronyms all over the place without explaining them. Since this is the first post I don’t really know who’s going to be reading this. I don’t want to waste time telling people what an SPI interface if they’re already fluent in µC speak. On the other hand I’d also like to encourage people who are new to the world of electronics and hardware hacking, which I was myself not that long ago.
I think what I’ll do is summarise what I’m doing concisely and then write more posts explaining various parts as the mood takes me.